#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll bitree[4][225816];
int t[225816],x[225816];
ll y[225816],a[2][225816];
std::vector<ll> v;

void update(int x, ll ret, int k){
	++x;
	while(x<225816){
		bitree[k][x] += ret;
		x += (x&(-x));
	}
}

ll query(int x, int k){
	ll ret = 0ll;
	++x;
	while(x){
		ret += bitree[k][x];
		x -= (x&(-x));
	}
	return ret;
}

int main(void){
	int n,m,q,i,l,r,p;
	ll ans = 0ll;
	std::cin >> n >> m >> q;
	v.push_back(0ll);
	update(0,n,0); update(0,m,1);
	for(i=0; i<q; ++i){
		std::cin >> t[i] >> x[i] >> y[i];
		--t[i]; --x[i];
		v.push_back(y[i]);
	}
	std::sort(v.begin(),v.end());
	for(i=0; i<q; ++i){
		r = (int)(std::lower_bound(v.begin(),v.end(),a[t[i]][x[i]])-v.begin());
		ans -= query(r,(1^t[i]))*a[t[i]][x[i]] + query(q+1,(3^t[i]))-query(r,(3^t[i]));
		update(r,-1ll,t[i]);
		update(r,-a[t[i]][x[i]],t[i]+2);
		a[t[i]][x[i]] = y[i];
		r = (int)(std::lower_bound(v.begin(),v.end(),y[i])-v.begin());
		ans += query(r,(1^t[i]))*a[t[i]][x[i]] + query(q+1,(3^t[i]))-query(r,(3^t[i]));
		update(r,1ll,t[i]);
		update(r,y[i],t[i]+2);
		std::cout << ans << std::endl;
	}
	return 0;
}

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
#define MOD 1000000007
using namespace std;

int main() {
  long long T; cin >> T;
  for (int i = 0; i < T; i++){
    long long N, A, B; cin >> N >> A >> B;
    if (N < A + B){
      cout << 0 << endl;
      continue;
    }
    long long p = ((N - A - B + 1) * (N - A - B + 2) * 2) % MOD;
    long long q = (N - A + 1) * (N - B + 1) % MOD;
    long long ans = (p * q) % MOD;
    long long r = (N - A - B + 1) * (N - A - B + 2) % MOD;
    ans -= (r * r) % MOD;
    ans = ((ans % MOD) + MOD) % MOD;;
    cout << ans << endl;
  }
}