#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
struct H{int i,x,y,r;};
int n,x[204],y[204],a[10005][10005];
H e[204];
int C(H a,H b){return a.y<b.y||a.y==b.y&&a.x<b.x;}
int D(H a,H b){return a.i<b.i;}
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		e[i].i=i;
		cin>>e[i].x>>e[i].y>>e[i].r;
	}
	sort(e,e+n,C);
	for(int k=0;k<n;k++)
	{
		int v=e[k].x,w=e[k].y;
		for(;w>=0&&!a[v][w];)w--;
		for(w++;v>=0&&!a[v][w];)v--;
		v++;
		x[e[k].i]=v;
		y[e[k].i]=w;
		for(int i=e[k].x;i>=v;i--)
		{
			for(int j=e[k].y;j>=w;j--)a[i][j]=1;
		}
	}
	sort(e,e+n,D);
	for(int i=0;i<n;i++)cout<<x[i]<<' '<<y[i]<<' '<<e[i].x+1<<' '<<e[i].y+1<<endl;
}
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#ifdef local
#define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define pary(a...) danb(#a, a)
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
    std::cerr << "\033[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        std::cerr << (f++ ? ", " : "") << *L;
    std::cerr << " ]\033[0m\n";
}
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#define pary(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define pb emplace_back
#define get_pos(u,x) int(lower_bound(all(u),x)-begin(u))

using namespace std;
using ll = int_fast64_t;
const int inf = 1e9;
const int mod = 1000000007;
const ll INF = 1e18;
const int maxn = 200025;

struct Fenwick {
    ll b[maxn];
    void add(int p, int d) {
        for (++p; p < maxn; p += p & -p)
            b[p] += d;
    }
    ll query(int p) {
        ll r = 0;
        for (++p; p > 0; p -= p & -p)
            r += b[p];
        return r;
    }
} cnt_a, cnt_b, sum_a, sum_b;

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m, q;
    cin >> n >> m >> q;
    vector<tuple<int,int,int>> Qs(q);
    vector<int> u;
    u.pb(0);
    for (auto &[t, x, y]: Qs) cin >> t >> x >> y, u.pb(y), --x;
    sort(all(u)), u.erase(unique(all(u)), u.end());
    vector<int> a(n), b(m);

    auto calc = [&](int val, Fenwick &cnt, Fenwick &sum) {
        int pos = get_pos(u, val);
        return val * cnt.query(pos - 1) + (sum.query(maxn - 2) - sum.query(pos - 1));
    };
    ll ans = 0;
    cnt_a.add(get_pos(u, 0), n);
    cnt_b.add(get_pos(u, 0), m);
    for (auto [t, x, y]: Qs) {
        if (t == 1) {
            cnt_a.add(get_pos(u, a[x]), -1);
            sum_a.add(get_pos(u, a[x]), -a[x]);
            ans -= calc(a[x], cnt_b, sum_b);
            a[x] = y;
            ans += calc(a[x], cnt_b, sum_b);
            cnt_a.add(get_pos(u, a[x]), 1);
            sum_a.add(get_pos(u, a[x]), a[x]);
        } else {
            cnt_b.add(get_pos(u, b[x]), -1);
            sum_b.add(get_pos(u, b[x]), -b[x]);
            ans -= calc(b[x], cnt_a, sum_a);
            b[x] = y;
            ans += calc(b[x], cnt_a, sum_a);
            cnt_b.add(get_pos(u, b[x]), 1);
            sum_b.add(get_pos(u, b[x]), b[x]);
        }
        cout << ans << '\n';
    }
}
