#include <stdio.h>
#include <vector>
#define MAX 10005
#define INF 1<<30
#define pb push_back
using namespace std;
vector<int> l[MAX];
vector<int> q;
int n, m, e, x, y, i, pair1[MAX], pair2[MAX], dist[MAX];
bool BFS();
bool DFS(int x);
int HK();
int main(){
freopen("cuplaj.in", "r", stdin);
freopen("cuplaj.out", "w", stdout);
scanf("%d%d%d", &n, &m, &e);
for(i = 0; i < e; i++){
scanf("%d%d", &x, &y);
l[x].pb(y);
}
printf("%d\n", HK());
for(i = 1; i <= n; i++)
if(pair1[i])
printf("%d %d\n", i, pair1[i]);
return 0;
}
bool BFS(){
for(i = 1; i <= n; i++){
if(!pair1[i]){
dist[i] = 0;
q.pb(i);
}
else
dist[i] = INF;
}
dist[0] = INF;
while(!q.empty()){
i = q.front();
q.erase(q.begin());
if(dist[i] < dist[0]){
vector<int>::iterator it = l[i].begin();
for(it; it < l[i].end(); it++)
if(dist[pair2[*it]] == INF){
dist[pair2[*it]] = dist[i] + 1;
q.pb(pair2[*it]);
}
}
}
return dist[0] != INF;
}
bool DFS(int x){
if(x != 0){
vector<int>::iterator it = l[x].begin();
for(it; it < l[x].end(); it++)
if(dist[pair2[*it]] == dist[x] + 1 && DFS(pair2[*it])){
pair2[*it] = x;
pair1[x] = *it;
return true;
}
dist[x] = INF;
return false;
}
return true;
}
int HK(){
int nr = 0;
while(BFS()){
for(i = 1; i <= n; i++)
if(!pair1[i] && DFS(i))
nr++;
}
return nr;
}