#include <bits/stdc++.h>
using namespace std;
const int nmax = 3e3 + 1;
vector<int> adj[nmax];
bool f[nmax];
int spre[nmax];
int de_la[nmax];
bool dfs(int i) {
if (f[i]) return false;
f[i] = 1;
for (auto it : adj[i]) {
if (!de_la[it]) {
de_la[it] = i;
spre[i] = it;
return 1;
}
}
for (auto it : adj[i]) {
if (dfs(de_la[it])) {
de_la[it] = i;
spre[i] = it;
return 1;
}
}
return 0;
}
int32_t main() {
ifstream cin("cuplaj.in");
ofstream cout("cuplaj.out");
int n, m, e;
cin >> n >> m >> e;
for (int i = 1; i <= e; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
}
bool ok = 1;
while (ok) {
ok = 0;
for (int i = 1; i <= n; i++) {
f[i] = 0;
}
for (int i = 1; i <= n; i++) {
if (!spre[i]) {
ok |= dfs(i);
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
ans += (spre[i] != 0);
}
cout << ans << '\n';
for (int i = 1; i <= n; i++) {
if (spre[i]) cout << i << " " << spre[i] << '\n';
}
return 0;
}