#include<fstream>
#include<cstring>
#include<vector>
using namespace std;
ifstream in("cuplaj.in");
ofstream out("cuplaj.out");
const int Nmax = 10001;
vector<int> G[Nmax];
int N,M,A[Nmax],B[Nmax],mark[Nmax];
int addpath(int x){
if(mark[x]) return 0;
mark[x]=1;
for(vector<int>::iterator it=G[x].begin();it!=G[x].end();++it){
if(!B[*it] || addpath(B[*it])){
A[x]=*it;
B[*it]=x;
return 1;
}
}
return 0;
}
int main(){
int edges;
in>>N>>M>>edges;
for(;edges;--edges){
int x,y;
in>>x>>y;
G[x].push_back(y);
}
int p=1,mf=0;
while(p){
p=0;
memset(mark,0,sizeof(mark));
for(int i=1;i<=N;i++) if(!A[i]) p|=addpath(i);
}
for(int i=1;i<=N;i++) if(A[i]) mf++;
out<<mf<<'\n';
for(int i=1;i<=N;i++) if(A[i]) out<<i<<' '<<A[i]<<'\n';
return 0;
}