#include <fstream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cuplaj.in");
ofstream fout("cuplaj.out");
int n, m, e, i, x, y, mt[100005], viz[100005], change, l[100005], cnt;
vector <int> g[100005];
vector <pair<int, int>> ans;
bool try_kuhn(int v)
{
if(viz[v]==1)
return false;
viz[v]=true;
for(auto i: g[v])
{
if(mt[i]==-1 || try_kuhn(i))
{
mt[i]=v;
l[v]=i;
return true;
}
}
return false;
}
int main()
{
fin>>n>>m>>e;
for(i=1; i<=e; i++)
{
fin>>x>>y;
g[x].push_back(y);
}
for(i=1; i<=m; i++)
mt[i]=-1;
for(i=1; i<=n; i++)
l[i]=-1;
change=1;
while(change)
{
change=0;
for(i=1; i<=n; i++)
viz[i]=0;
for(i=1; i<=n; i++)
if(l[i]==-1)
change|=try_kuhn(i);
}
for(i=1; i<=m; i++)
if(mt[i]>0)
cnt++;
fout<<cnt<<'\n';
for(i=1; i<=m; i++)
ans.push_back({mt[i], i});
sort(ans.begin(), ans.end());
for(auto i: ans)
fout<<i.first<<" "<<i.second<<'\n';
// fout<<mt[i]<<" "<<i<<'\n';
return 0;
}