// This code is AI-generated. (AI 生成的代码)
// NOIP2017 列队: offline. For each row and for the last column, replay only the
// queries that touch it through a Fenwick "select k-th present / remove", which
// maps each request to either an original position or an appended slot. Then
// replay all queries, resolving appended slots with per-row / last-column vectors.
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
enum { MAXN = 300005 };
struct Req { int qid, x; };
static vector<Req> rowReq[MAXN];
static vector<Req> colReq;
static int ind[2 * MAXN];
static int qx[MAXN], qy[MAXN];
static int fw[1 << 21];
static int FW;
static inline int lowbit(int x) { return x & -x; }
static void rebuild(int size) {
FW = 1; while (FW < size) FW <<= 1;
for (int i = 1; i <= FW; i++) fw[i] = lowbit(i);
}
static int rmv(int k) {
int pos = 0, rem = k;
for (int pw = FW >> 1; pw; pw >>= 1)
if (pos + pw <= FW && fw[pos + pw] < rem) { pos += pw; rem -= fw[pos]; }
int p = pos + 1;
for (int i = p; i <= FW; i += lowbit(i)) fw[i]--;
return p;
}
static void addp(int p) { for (int i = p; i <= FW; i += lowbit(i)) fw[i]++; }
int main() {
int n, m, q;
scanf("%d%d%d", &n, &m, &q);
int qc = 0;
for (int i = 1; i <= q; i++) {
scanf("%d%d", &qx[i], &qy[i]);
if (qy[i] == m) colReq.push_back(Req{++qc, qx[i]});
else {
rowReq[qx[i]].push_back(Req{++qc, qy[i]});
colReq.push_back(Req{++qc, qx[i]});
}
}
rebuild(m + q + 2);
for (int i = 1; i <= n; i++) {
for (size_t j = 0; j < rowReq[i].size(); j++) ind[rowReq[i][j].qid] = rmv(rowReq[i][j].x);
for (size_t j = 0; j < rowReq[i].size(); j++) addp(ind[rowReq[i][j].qid]);
}
rebuild(n + q + 2);
for (size_t j = 0; j < colReq.size(); j++) ind[colReq[j].qid] = rmv(colReq[j].x);
static vector<ll> rr[MAXN];
static vector<ll> rc;
qc = 0;
for (int i = 1; i <= q; i++) {
if (qy[i] == m) {
++qc; ll v;
if (ind[qc] <= n) v = (ll)ind[qc] * m; else v = rc[ind[qc] - n - 1];
rc.push_back(v); printf("%lld\n", v);
} else {
++qc; ll v;
if (ind[qc] < m) v = (ll)ind[qc] + (ll)(qx[i] - 1) * m;
else v = rr[qx[i]][ind[qc] - m];
printf("%lld\n", v); rc.push_back(v);
++qc;
if (ind[qc] <= n) v = (ll)ind[qc] * m; else v = rc[ind[qc] - n - 1];
rr[qx[i]].push_back(v);
}
}
return 0;
}