#include <bits/stdc++.h>
using namespace std;
ifstream in("maxflow.in");
ofstream out("maxflow.out");
const int NMAX = 1e4;
int a, b, m;
vector<int> G[NMAX + 1];
int flux[NMAX + 1][NMAX + 1];
int capacitate[NMAX + 1][NMAX + 1];
int p[NMAX + 1], vis[NMAX + 1];
int ek(int sursa, int destinatie){
for(int i = 0; i <= a + b + 1; i++){
p[i] = 0;
vis[i] = 0;
}
queue<int> q;
q.push(sursa);
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[destinatie] == 0){
return 0;
}
vector<int> drum;
int x = destinatie;
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 <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 < 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(){
in >> a >> b >> m;;
for(int i = 1; i <= m; i++){
int x, y;
cin >> x >> y;
G[x].push_back(x + y);
capacitate[x][x + y] = 1;
G[x + 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(a + b + 1);
capacitate[i][a + b + 1] = 1;
G[a + b + 1].push_back(i);
}
n = a + b + 1;
int sum = 0;
while(true){
int flux = ek(0, n);
if(flux == 0){
break;
}
sum += flux;
}
cout << sum << '\n';
for(int i = 1; i <= a; i++){
for(int j = a + 1; j <= a + b; j++){
if(flux[i][j] == 1){
cout << i << " " << j - a << "\n";
}
}
}
}