#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
constexpr int N = 3e5 + 7;
#define lc c[0]
#define rc c[1]
struct Node { int c[2], fa; bool rev; } t[N];
int S[N];
bool isroot(int o) { return t[t[o].fa].lc != o && t[t[o].fa].rc != o; }
bool idtfy(int o) { return t[t[o].fa].rc == o; }
void connect(int fa, int o, int d) { t[fa].c[d] = o, t[o].fa = fa; }
void pushup(int o) { }
void pushdown(int o) {
if (!t[o].rev) return;
t[o].rev = 0;
if (t[o].lc) swap(t[t[o].lc].lc, t[t[o].lc].rc), t[t[o].lc].rev ^= 1;
if (t[o].rc) swap(t[t[o].rc].lc, t[t[o].rc].rc), t[t[o].rc].rev ^= 1;
}
void rotate(int o) {
int fa = t[o].fa, pa = t[fa].fa, d1 = idtfy(o), d2 = idtfy(fa), b = t[o].c[d1 ^ 1];
t[o].fa = pa, !isroot(fa) && (t[pa].c[d2] = o);
connect(fa, b, d1), connect(o, fa, d1 ^ 1);
pushup(fa), pushup(o);
}
void splay(int o) {
int x = o, tp = 1;
S[tp] = x;
while (!isroot(x)) S[++tp] = x = t[x].fa;
while (tp) pushdown(S[tp--]);
while (!isroot(o)) {
int fa = t[o].fa;
if (isroot(fa)) rotate(o);
else if (idtfy(o) == idtfy(fa)) rotate(fa), rotate(o);
else rotate(o), rotate(o);
}
}
void access(int o) {
for (int x = 0; o; x = o, o = t[o].fa)
splay(o), t[o].rc = x, pushup(o);
}
int findrt(int x) {
access(x), splay(x);
while (pushdown(x), t[x].lc) x = t[x].lc;
return splay(x), x;
}
void mkrt(int x) {
access(x), splay(x);
t[x].rev ^= 1, swap(t[x].lc, t[x].rc);
}
int findfa(int x) {
access(x), splay(x);
pushdown(x), x = t[x].lc;
while (pushdown(x), t[x].rc)
{
x = t[x].rc;
}
if (x) splay(x);
return x;
}//找到前驱
void split(int x, int y) { mkrt(x), access(y), splay(y); }
void link(int x, int y) {
access(x), splay(x), t[x].fa = y;
}
void cut(int x, int y) {
access(x), splay(x);
t[x].lc = t[t[x].lc].fa = 0;
if (t[y].lc == x && t[x].fa == y) t[y].lc = t[x].fa = 0, pushup(y);
}
using pii = pair<int, int>;
int n, m, q, nod;
int bl[N];
set<pii> ps[N];
int get(int id, int x) {
set<pii> &s = ps[id];
pii u(x, 0);
auto p = s.upper_bound(u);
if (p->first == x)
{
return p->second;
}
cout << "info p = " << p -> first << " " << p->second << endl;
int old = p->second, oldv = p->first;
s.erase(p);
++nod;
bl[nod] = id;
int fa = findfa(old);
cout << x << " " << old << " " << nod << " " << fa << endl;
if (fa) cut(old, fa);
link(old, nod);
if (fa) link(nod, fa);
s.emplace(x, old);
s.emplace(oldv, nod);
return old;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> q;
for (int i = 1; i <= n; ++i) ++nod, ps[i].emplace(m + 1, nod), bl[nod] = i;
for (int i = 1; i <= q; ++i) {
int opt, a, b;
cin >> opt;
if (opt == 1) {
cin >> a >> b;
int v1 = get(a, b), v2 = get(a + 1, b);
int f1 = findfa(v1), f2 = findfa(v2);
if (f1) cut(v1, f1);
if (f2) cut(v2, f2);
if (f2) link(v1, f2);
if (f1) link(v2, f1);
} else {
cin >> a;
cout << bl[findrt(ps[a].begin()->second)] << '\n';
}
}
return 0;
}