#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
using namespace std;
#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "cuplaj";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif
typedef pair<int, int> PII;
const int NMAX = 10000 + 5;
int N, M, E;
vector<int> A[NMAX];
vector<int> B[NMAX];
int P[NMAX];
int Q[NMAX];
vector<PII> sol;
bitset<NMAX> viz;
int pair_up(int x) {
if(viz[x])
return 0;
viz[x] = 1;
for(auto y : A[x]) {
if((!Q[y]) || (pair_up(Q[y]))) {
P[x] = y;
Q[y] = x;
return 1;
}
}
return 0;
}
int main() {
int i, ok, x, y;
freopen(inputFile.c_str(), "r", stdin);
freopen(outputFile.c_str(), "w", stdout);
scanf("%d%d%d", &N, &M, &E);
while(E--) {
scanf("%d%d", &x, &y);
A[x].push_back(y);
B[y].push_back(x);
}
do {
ok = 0;
viz = 0;
for(i = 1; i <= N; i++)
if(!P[i])
ok |= pair_up(i);
} while(ok);
for(i = 1; i <= N; i++)
if(P[i])
sol.push_back(make_pair(i, P[i]));
printf("%d\n", sol.size());
for(auto p : sol)
printf("%d %d\n", p.first, p.second);
return 0;
}