#include<cstdio>
#include<cctype>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=0,f=1;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c==‘-‘) f=-1;
for(;isdigit(c);c=Getchar()) x=x*10+c-‘0‘;
return x*f;
}
typedef long long ll;
const int maxn=30010;
const int maxm=300010;
const int HASH=233233;
const int inf=2147483647;
struct Hash_Map {
int first[HASH],next[maxm],valx[maxm],valy[maxm],cnt;
int find(int x,int y) {
int p=(x%HASH+y%HASH)%HASH;if(p<0) p+=HASH;
for(int i=first[p];i;i=next[i]) if(valx[i]==x&&valy[i]==y) return i;
valx[++cnt]=x;valy[cnt]=y;next[cnt]=first[p];
return first[p]=cnt;
}
}M;
int n,val[maxn],pos[maxn],ans1[maxn],ans2[maxn];
void update(int x,int v1,int v2) {
ans1[x]=max(ans1[x],v1);
ans2[x]=max(ans2[x],v2);
}
struct Node {
Node* ch[2];
int r,x,maxv,maxs;
int s,mx;
void relax(int v1,int v2) {
maxs=max(maxs,v1);
maxv=max(maxv,v2);
update(x,maxs,maxv);
}
void pushdown() {
if(ch[0]->maxs!=inf) ch[0]->relax(maxs,maxv);
if(ch[1]->maxs!=inf) ch[1]->relax(maxs,maxv);
update(x,maxs,maxv);
maxv=maxs=0;
}
void maintain() {
s=ch[0]->s+ch[1]->s+1;
mx=max(val[x],max(ch[0]->mx,ch[1]->mx));
}
}nodes[maxn],*null=&nodes[0];
queue<Node*> Q;
Node* newnode(int v) {
Node* o=Q.front();Q.pop();
o->maxv=o->maxs=0;
o->ch[0]=o->ch[1]=null;
o->r=rand();o->x=v;o->s=1;o->mx=val[v];
return o;
}
void del(Node* &o) {Q.push(o);o=null;}
void rotate(Node* &o,int d) {
Node* k=o->ch[d^1];o->pushdown();k->pushdown();
o->ch[d^1]=k->ch[d];k->ch[d]=o;
o->maintain();k->maintain();o=k;
}
void insert(Node* &o,int v) {
if(o==null) o=newnode(v);
else {
o->pushdown();
int d=v>o->x;insert(o->ch[d],v);
if(o->ch[d]->r>o->r) rotate(o,d^1);
}
o->maintain();
}
void remove(Node* &o,int v) {
o->pushdown();
if(o->x==v) {
Node *k=o;
if(o->ch[0]==null) o=o->ch[1],del(k);
else if(o->ch[1]==null) o=o->ch[0],del(k);
else {
int d=o->ch[0]->r>o->ch[1]->r;
rotate(o,d);remove(o->ch[d],v);
}
}
else remove(o->ch[v>o->x],v);
if(o!=null) o->maintain();
}
void force(Node* &o) {
if(o==null) return;
o->pushdown();
force(o->ch[0]);
force(o->ch[1]);
}
Node* root[maxm];
int main() {
null->maxs=null->maxv=inf;
null->s=0;null->mx=-inf;
rep(i,1,maxn-1) Q.push(&nodes[i]);
rep(i,0,maxm-1) root[i]=null;
n=read();
rep(i,1,n) {
val[i]=read();int x=read(),y=read(),T=M.find(x,y);
if(root[T]!=null) {
update(i,0,root[T]->mx);
root[T]->relax(0,val[i]);
}
insert(root[pos[i]=T],i);
root[T]->relax(root[T]->s-1,0);
}
dwn(i,read(),1) {
int c=read(),x=read(),y=read(),T=M.find(x,y);
if(T==pos[c]) continue;
remove(root[pos[c]],c);
if(root[T]!=null) {
update(c,0,root[T]->mx);
root[T]->relax(0,val[c]);
}
insert(root[pos[c]=T],c);
root[T]->relax(root[T]->s-1,0);
}
rep(i,1,M.cnt) force(root[i]);
rep(i,1,n) printf("%lld\n",(ll)ans2[i]*ans1[i]);
return 0;
}