#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define rep(i,l,r) for(int i=l;i<r;++i)
#define sz(v) (int)((v).size())
#define vi vector<int>
using namespace std;
class InputReader {
public:
InputReader() {
input_file = stdin;
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
InputReader(const char *file_name) {
input_file = fopen(file_name, "r");
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
template<typename T>
inline InputReader &operator >>(T &n) {
while ((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
advance();
}
int sign = 1;
if (buffer[cursor] == '-') {
sign = -1;
advance();
}
n = 0;
while ('0' <= buffer[cursor] && buffer[cursor] <= '9') {
n = n * 10 + buffer[cursor] - '0';
advance();
}
n *= sign;
return *this;
}
private:
FILE *input_file;
static const int SIZE = 1 << 17;
int cursor;
char buffer[SIZE];
inline void advance() {
++cursor;
if (cursor == SIZE) {
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
}
};
bool dfs(int a, int L, vector<vi>& g, vi& btoa, vi& A, vi& B) {
if (A[a] != L) return 0;
A[a] = -1;
for (int b : g[a]) if (B[b] == L + 1) {
B[b] = 0;
if (btoa[b] == -1 || dfs(btoa[b], L + 1, g, btoa, A, B))
return btoa[b] = a, 1;
}
return 0;
}
int hopcroftKarp(vector<vi>& g, vi& btoa) {
int res = 0;
vi A(g.size()), B(btoa.size()), cur, next;
for (;;) {
fill(all(A), 0);
fill(all(B), 0);
/// Find the starting nodes for BFS (i.e. layer 0).
cur.clear();
for (int a : btoa) if(a != -1) A[a] = -1;
rep(a,0,sz(g)) if(A[a] == 0) cur.push_back(a);
/// Find all layers using bfs.
for (int lay = 1;; lay++) {
bool islast = 0;
next.clear();
for (int a : cur) for (int b : g[a]) {
if (btoa[b] == -1) {
B[b] = lay;
islast = 1;
}
else if (btoa[b] != a && !B[b]) {
B[b] = lay;
next.push_back(btoa[b]);
}
}
if (islast) break;
if (next.empty()) return res;
for (int a : next) A[a] = lay;
cur.swap(next);
}
/// Use DFS to scan for augmenting paths.
rep(a,0,sz(g))
res += dfs(a, 0, g, btoa, A, B);
}
}
int main() {
InputReader cin("cuplaj.in");
ofstream cout("cuplaj.out");
int n, m, k; cin >> n >> m >> k;
vector<vector<int>> graph(n);
for (int i = 0; i < k; ++i) {
int a, b; cin >> a >> b; --a; --b;
graph[a].push_back(b);
}
vector<int> btoa(m, -1);
cout << hopcroftKarp(graph, btoa) << endl;
for (int i = 0; i < m; ++i)
if (btoa[i] != -1)
cout << btoa[i] + 1 << " " << i + 1 << '\n';
return 0;
}