#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, m, q, c[N], p[N];
multiset<int, greater<int>> st[N], se, mx;
long long res, ans;
void add(int x) {
auto it = st[x].begin();
if (st[x].size()) {
mx.insert(*it);
res += (*it);
}
if (st[x].size() > 1) {
it++;
se.insert(*it);
}
return;
}
void del(int x) {
auto it = st[x].begin();
if (st[x].size()) {
auto tmp = mx.lower_bound(*it);
res -= (*it); mx.erase(tmp);
}
if (st[x].size() > 1) {
++it;
auto tmp = se.lower_bound(*it);
se.erase(tmp);
}
return;
}
int mn() {
auto it = mx.end();
it--;
return (*it);
}
long long calc() {
ans = res;
if (se.size()) {
ans = max(ans, res - mn() + (*se.begin()));
}
return ans;
}
int main() {
freopen("Pens.in", "r", stdin);
freopen("Pens.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m >> q;
for (int i = 1; i <= n; i++) {
cin >> c[i] >> p[i];
st[c[i]].insert(p[i]);
}
for (int i = 1; i <= m; i++) add(i);
int o, x, y; cout << calc() << '\n';
while (q--) {
cin >> o >> x >> y;
if (o == 1) {
del(c[x]), del(y);
auto it = st[c[x]].lower_bound(p[x]);
st[c[x]].erase(it);
st[y].insert(p[x]);
add(c[x]), add(y);
c[x] = y;
} else if (o == 2) {
del(c[x]);
auto it = st[c[x]].lower_bound(p[x]);
st[c[x]].erase(it);
p[x] = y; st[c[x]].insert(p[x]);
add(c[x]);
}
cout << calc() << '\n';
}
return 0;
}