#include<bits/stdc++.h>
using namespace std;
ifstream fin("cuplaj.in");
ofstream fout("cuplaj.out");
const int NMAX = 20005;
vector <int> G[NMAX + 1];
int flux[NMAX + 1][NMAX + 1];
int p[NMAX + 1], vis[NMAX + 1];
int a, b, m, n;
int capacitate[NMAX + 1][NMAX + 1];
int ek(int sursa, int dest){
for(int i = 0; i <= n; i++){
p[i] = 0;
vis[i] = 0;
}
queue<int> q;
q.push(sursa);
vis[sursa] = 1;
while(!q.empty()){
int node = q.front();
q.pop();
for(auto vec : G[node]){
if(!vis[vec] && capacitate[node][vec] - flux[node][vec] > 0){
q.push(vec);
vis[vec] = 1;
p[vec] = node;
}
}
}
if(vis[dest] == 0){
return 0;
}
vector<int> drum;
int x = dest;
while(x != sursa){
drum.push_back(x);
x = p[x];
}
drum.push_back(sursa);
reverse(drum.begin(), drum.end());
int flow = 1e9;
for(int i = 0; i < (int)drum.size() - 1; i++){
int x = drum[i];
int y = drum[i+1];
int val = capacitate[x][y] - flux[x][y];
if(val < flow){
flow = val;
}
}
for(int i = 0; i < (int)drum.size() - 1; i++){
int x = drum[i];
int y = drum[i+1];
flux[x][y] += flow;
flux[y][x] -= flow;
}
return flow;
}
int main(){
fin >> a >> b >> m;
n = a + b + 1;
for(int i = 1; i <= m; i++){
int x, y;
fin >> x >> y;
G[x].push_back(a + y);
capacitate[x][a + y] = 1;
G[a + y].push_back(x);
}
for (int i = 1; i <= a; i++) {
G[0].push_back(i);
capacitate[0][i] = 1;
G[i].push_back(0);
}
for (int i = a + 1; i <= a + b; i++) {
G[i].push_back(n);
capacitate[i][n] = 1;
G[n].push_back(i);
}
int sum = 0;
while(true){
int f = ek(0, n);
if(f == 0){
break;
}
sum += f;
}
fout << sum << "\n";
for(int i = 1; i <= a; i++){
for(auto vec : G[i]){
if(vec > a && vec <= a + b && flux[i][vec] > 0){
fout << i << " " << vec - a << "\n";
}
}
}
return 0;
}