#include <fstream>
#include <vector>
using namespace std;
const string filename = "cuplaj";
ifstream fin(filename + ".in");
ofstream fout(filename + ".out");
const int maxN = 10005;
int n1, n2, m, l[maxN], r[maxN];
vector <int> G[maxN];
bool used[maxN];
bool pairup(int nod)
{
if(used[nod])
return 0;
used[nod] = 1;
for(int vecin : G[nod])
{
if(!r[vecin])
{
l[nod] = vecin;
r[vecin] = nod;
return 1;
}
}
for(int vecin : G[nod])
{
if(pairup(r[vecin]))
{
l[nod] = vecin;
r[vecin] = nod;
return 1;
}
}
return 0;
}
int main()
{
fin >> n1 >> n2 >> m;
for(int i = 1; i <= m; i++)
{
int x, y;
fin >> x >> y;
G[x].push_back(y);
}
bool changed = 1;
while(changed)
{
changed = 0;
for(int i = 1; i <= n1; i++)
used[i] = 0;
for(int i = 1; i <= n1; i++)
if(!l[i])
changed |= pairup(i);
}
int total = 0;
for(int i = 1; i <= n1; i++)
if(l[i])
total++;
fout << total << '\n';
for(int i = 1; i <= n1; i++)
if(l[i])
fout << i << ' ' << l[i] << '\n';
return 0;
}