#include <bits/stdc++.h>
using namespace std;
ifstream f("cuplaj.in");
ofstream g("cuplaj.out");
vector <int> v[10009];
int st[10009], dr[10009], tried[10009];
int n, m, q, ans;
bool augment (int nod)
{
if (tried[nod])
return 0;
tried[nod]=1;
//cout << nod << ' ';
for (auto y:v[nod])
{
if (!st[y])
{
dr[nod]=y;
st[y]=nod;
ans++;
return 1;
}
}
for (auto y:v[nod])
{
if (augment (st[y]))
{
st[y]=nod;
dr[nod]=y;
return 1;
}
}
return 0;
}
void cuplaj ()
{
bool ok=1;
while (ok)
{
ok=0;
for (int i=1; i<=n; i++)
tried[i]=0;
for (int i=1; i<=n; i++)
if (!dr[i]) ok|=augment(i);
}
}
signed main ()
{
f >> n >> m >> q;
while (q--)
{
int a, b;
f >> a >> b;
v[a].push_back(b);
}
cuplaj ();
g << ans<<'\n';
for (int i=1; i<=n; i++)
{
if (dr[i]) g << i << ' ' << dr[i] << '\n';
}
}