#include <bits/stdc++.h>
// limit
#define mod1 22439423LL
#define mod2 42342432LL
#define mod3 56454765LL
#define mod4 66867574LL
#define oo 1000000001
#define OO 1000000000000000007LL
#define maxN 107
// loop
#define fto(i, x, y) for(int i = (x); i <= (y); ++i)
#define fdto(i, x, y) for(int i = (x); i >= (y); --i)
#define ftoa(i, x, y, a) for(int i = (x); i <= (y); i += a)
#define fdtoa(i, x, y, a) for(int i = (x); i >= (y); i -= a)
#define ftosqrt(i, x, y) for(int i = (x); i*i <= (y); ++i)
#define ftoit(it, var) for (__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)
#define fdtoit(rit, var) for (__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); ++rit)
// debug
#define debug cout << "*" << endl;
#define bug1d(a, x, y) { cout << #a << ": "; fto(_, x, y) cout << a[_] << ' '; cout << endl; }
#define bug2d(a, x, y, u, v) { cout << #a << ": " << endl; fto(i, x, y) {fto(j, u, v) cout << a[i][j] << ' '; cout << endl;}; cout << endl;}
#define bug(a) cout << #a << " = " << a << endl;
#define bug2(a, b) cout << #a << " = " << a << "; "; cout << #b << " = " << b << endl;
#define bug3(a, b, c) cout << #a << " = " << a << "; "; cout << #b << " = " << b << "; "; cout << #c << " = " << c << endl;
// operation
#define mp make_pair
#define pb push_back
#define pf push_front
// structure
#define ii pair<int, int>
#define iii pair<ii, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define matrix vector<vi>
// get value
#define FF first
#define SS second
// data type
#define ll long long
#define ull unsigned long long
// function
#define lb lower_bound
#define ub upper_bound
// const value
#define pi 3.14159265358979323846264338327950288419716939937510
using namespace std;
template <class T>
T min(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T min(T a, T b, T c, T d) {
return min(a, min(b, min(c, d)));
}
template <class T>
T max(T a, T b, T c) {
return max(a, max(b, c));
}
template <class T>
T max(T a, T b, T c, T d) {
return max(a, max(b, max(c, d)));
}
bool cmp(const ii& a, const ii& b) {return (a.FF > b.FF || (a.FF == b.FF && a.SS >= b.SS));}
ll GCD(ll a, ll b) {return (a%b) ? GCD(b, a%b) : b;}
const string namePro = "rect";
int n, m, k;
int h[maxN], w[maxN];
bool isCheck[maxN][maxN];
int ans, res, cnt_fill, cnt_check;
ii trace[maxN], bestTrace[maxN];
bool inBound(int type, int x, int y) {
fto (i, x, x+h[type]-1) {
fto (j, y, y+w[type]-1) {
++cnt_check;
if (isCheck[i][j]) return 0;
}
}
return 1;
}
void check(int type, int x, int y) {
fto (i, x, x+h[type]-1) {
fto (j, y, y+w[type]-1) {
++cnt_fill;
isCheck[i][j] = 1;
}
}
return;
}
void uncheck(int type, int x, int y) {
fto (i, x, x+h[type]-1) {
fto (j, y, y+w[type]-1) {
++cnt_fill;
isCheck[i][j] = 0;
}
}
return;
}
void brute_force(int x) {
if (x > k) {
if (ans < res) {
ans = res;
// int cnt = 0;
fto (i, 1, k) {
// if (trace[i] != mp(0, 0)) ++cnt;
bestTrace[i] = trace[i];
}
// if (cnt != res) {
// fto (i, 1, k) cout << trace[i].FF << " " << trace[i].SS << endl;
// exit(0);
// }
}
return;
}
if (ans == k) return;
fto (i, 1, n-h[x]+1) {
fto (j, 1, m-w[x]+1) {
bool tmp = inBound(x, i, j);
if (tmp) check(x, i, j);
if (tmp) ++res;
if (tmp) trace[x] = mp(i, j);
if (tmp) brute_force(x+1);
trace[x] = mp(0, 0);
if (tmp) uncheck(x, i, j);
if (tmp) --res;
}
}
brute_force(x+1);
return;
}
int main() {
#ifndef ONLINE_JUDGE
freopen((namePro+".inp").c_str(), "r", stdin);
freopen((namePro+".out").c_str(), "w", stdout);
#endif // ONLINE_JUDGE
scanf("%d%d%d", &n, &m, &k);
fto (i, 1, k) scanf("%d%d", &h[i], &w[i]);
brute_force(1);
//cout << ans << endl;
//cout << cnt_fill << " " << cnt_check << endl;
printf("%d\n", k);
fto (i, 1, k) printf("%d %d\n", bestTrace[i].FF, bestTrace[i].SS);
return 0;
}
I2luY2x1ZGUgPGJpdHMv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