#include <bits/stdc++.h>
using namespace std;
ifstream f("cuplaj.in");
ofstream g("cuplaj.out");
const int NMAX = 1e5 + 5;
int N, M, X, Y, K, St[NMAX], Dr[NMAX], ans;
bool Use[NMAX];
vector < int > G[NMAX];
int cupleaza(int nod)
{
Use[nod] = true;
for(auto i : G[nod])
if(!Dr[i])
{
St[nod] = i;
Dr[i] = nod;
return 1;
}
for(auto i : G[nod])
if(!Use[Dr[i]] && cupleaza(Dr[i]))
{
St[nod] = i;
Dr[i] = nod;
return 1;
}
return 0;
}
int Cuplaj_Maxim()
{
ans = 0;
bool ok = true;
while (ok)
{
ok = false;
memset(Use, false, sizeof(Use));
for(int i = 1 ; i<=N; i++)
if(!Use[i] && !St[i])
ok |= cupleaza(i);
}
for(int i = 1 ; i<=N; i++)
if(St[i])ans++;
return ans;
}
int main()
{
f >> N >> M >> K;
for(int i = 1; i <= K; ++i)
{
f >> X >> Y;
G[X].push_back(Y);
}
ans = Cuplaj_Maxim();
g << ans << '\n';
for(int i = 1; i <= N; ++i)
if(St[i])
g << i << ' ' << St[i] << '\n';
return 0;
}