#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream ka("cuplaj.in");
ofstream ki("cuplaj.out");
const int N_MAX = 10000;
vector<int> graf[N_MAX + 1];
int n, m, e, x, y;
int pair_n[N_MAX + 1], pair_m[N_MAX + 1];
bool vazut[N_MAX + 1];
int cuplaj;
bool pairup(int t)
{
if(vazut[t])
return false;
vazut[t] = true;
for(int i = 0; i < graf[t].size(); i++)
if(!pair_m[graf[t][i]])
{
pair_n[t] = graf[t][i];
pair_m[graf[t][i]] = t;
return true;
}
for(int i = 0; i < graf[t].size(); i++)
if(pairup(pair_m[graf[t][i]]))
{
pair_n[t] = graf[t][i];
pair_m[graf[t][i]] = t;
return true;
}
return false;
}
int main()
{
ka >> n >> m >> e;
for(int i = 1; i <= e; i++)
{
ka >> x >> y;
graf[x].push_back(y);
}
bool gasit = true;
while(gasit)
{
gasit = false;
for(int i = 1; i <= n; i++)
vazut[i] = false;
for(int i = 1; i <= n; i++)
if(!pair_n[i])
gasit |= pairup(i);
}
for(int i = 1; i <= n; i++)
if(pair_n[i])
cuplaj++;
ki << cuplaj << '\n';
for(int i = 1; i <= n; i++)
if(pair_n[i])
ki << i << " " << pair_n[i] << '\n';
}