#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
int Time(){
return chrono::steady_clock::now().time_since_epoch().count();
}
random_device rd;
mt19937_64 gen(rd());
int uniform_rand(int l, int r){
uniform_int_distribution<ll> rnd(l,r);
return rnd(gen);
}
const int NMAX=2e4+5,MMAX=1e5+5;
ifstream fin("cuplaj.in");
ofstream fout("cuplaj.out");
vector<ll> edg[NMAX*4+MMAX*2];
struct edge{
ll v,cap;
}edges[NMAX];
ll s,t,ans,dist[NMAX],ptr[NMAX];
ll flux(ll u,ll f){
if(f==0 || u==t) return f;
for(ll& i=ptr[u];i<edg[u].size();i++){
ll it=edg[u][i];
if(dist[edges[it].v]==dist[u]+1 && edges[it].cap){
ll augment=flux(edges[it].v,min(f,edges[it].cap));
if(augment==0) continue;
edges[it].cap-=augment;
edges[it^1].cap+=augment;
return augment;
}
}
return 0;
}
int main()
{
ios_base::sync_with_stdio(false); fin.tie(0);
ll n,m,e,id=0;
fin>>n>>m>>e;
for(ll i=0;i<e;i++){
ll u,v;
fin>>u>>v;
v+=n;
edges[id]={v,1};
edges[id^1]={u,0};
edg[u].push_back(id), edg[v].push_back(id^1);
id+=2;
}
for(ll i=1;i<=n;i++){
edges[id]={i,1};
edges[id^1]={0,0};
edg[0].push_back(id), edg[i].push_back(id^1);
id+=2;
}
for(ll i=n+1;i<=n+m;i++){
edges[id]={n+m+1,1};
edges[id^1]={i,0};
edg[i].push_back(id), edg[n+m+1].push_back(id^1);
id+=2;
}
s=0,t=n+m+1;
while(1){
for(ll i=0;i<=n+m+1;i++) dist[i]=-1,ptr[i]=0;
queue<ll> q;
q.push(s),dist[s]=0;
while(!q.empty()){
for(auto it : edg[q.front()]){
if(dist[edges[it].v]==-1 && edges[it].cap>0){
dist[edges[it].v]=dist[q.front()]+1;
q.push(edges[it].v);
}
}
q.pop();
}
if(dist[t]==-1) break;
ll f=0;
while((f=flux(s,INT_MAX))>0)
ans+=f;
}
fout<<ans<<'\n';
for(ll i=1;i<=n;i++){
for(auto it : edg[i]){
if(edges[it].cap==0 && edges[it].v>n && edges[it].v<=n+m){
fout<<i<<' '<<edges[it].v-n<<'\n';
}
}
}
return 0;
}