#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#define rg register
inline int read(){
	rg int x=0,fh=1;
	rg char ch=getchar();
	while(ch<'0' || ch>'9'){
		if(ch=='-') fh=-1;
		ch=getchar();
	}
	while(ch>='0' && ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*fh;
}
const int maxn=1e4+5;
bool vis[maxn][maxn];
int n,x[maxn],y[maxn],r[maxn],ax[maxn],ay[maxn],bx[maxn],by[maxn];
int main(){
	n=read();
	for(rg int i=1;i<=n;i++) x[i]=read(),y[i]=read(),r[i]=read();
	for(rg int i=1;i<=n;i++) ax[i]=x[i],ay[i]=y[i],bx[i]=x[i]+1,by[i]=y[i]+1;
	for(rg int i=1;i<=n;i++){
		for(rg int j=ax[i];j<=bx[i];j++){
			for(rg int k=ay[i];k<=by[i];k++){
				vis[j][k]=1;
			}
		}
	}
	rg int nsum=0;
	for(rg int i=1;i<=n;i++){
		while(ax[i]>=1){
			nsum=(bx[i]-ax[i]+1)*(by[i]-ay[i]+1);
			rg int jud=1;
			for(rg int j=ay[i];j<=by[i];j++){
				if(vis[ax[i]-1][j]==1) jud=0;
			}
			if(!jud) break;
			rg double tmp1=(double)std::min(nsum,r[i])/(double)std::max(nsum,r[i]);
			rg double tmp2=(double)std::min(nsum+by[i]-ay[i]+1,r[i])/(double)std::max(nsum+by[i]-ay[i]+1,r[i]);
			if((1-tmp1*tmp1)*(1-tmp1*tmp1)>(1-tmp2*tmp2)*(1-tmp2*tmp2)){
				nsum+=by[i]-ay[i]+1;
				for(rg int j=ay[i];j<=by[i];j++){
					vis[ax[i]-1][j]=1;
				}
				ax[i]--;
			} else {
				break;
			}
		}
		while(ay[i]>=1){
			nsum=(bx[i]-ax[i]+1)*(by[i]-ay[i]+1);
			rg int jud=1;
			for(rg int j=ax[i];j<=bx[i];j++){
				if(vis[j][ay[i]-1]==1) jud=0;
			}
			if(!jud) break;
			rg double tmp1=(double)std::min(nsum,r[i])/(double)std::max(nsum,r[i]);
			rg double tmp2=(double)std::min(nsum+bx[i]-ax[i]+1,r[i])/(double)std::max(nsum+bx[i]-ax[i]+1,r[i]);
			if((1-tmp1*tmp1)*(1-tmp1*tmp1)>(1-tmp2*tmp2)*(1-tmp2*tmp2)){
				nsum+=bx[i]-ax[i]+1;
				for(rg int j=ax[i];j<=bx[i];j++){
					vis[j][ay[i]-1]=1;
				}
				ay[i]--;
			} else {
				break;
			}
		}
		while(bx[i]<=9999){
			nsum=(bx[i]-ax[i]+1)*(by[i]-ay[i]+1);
			rg int jud=1;
			for(rg int j=ay[i];j<=by[i];j++){
				if(vis[bx[i]+1][j]==1) jud=0;
			}
			if(!jud) break;
			rg double tmp1=(double)std::min(nsum,r[i])/(double)std::max(nsum,r[i]);
			rg double tmp2=(double)std::min(nsum+by[i]-ay[i]+1,r[i])/(double)std::max(nsum+by[i]-ay[i]+1,r[i]);
			if((1-tmp1*tmp1)*(1-tmp1*tmp1)>(1-tmp2*tmp2)*(1-tmp2*tmp2)){
				nsum+=by[i]-ay[i]+1;
				for(rg int j=ay[i];j<=by[i];j++){
					vis[bx[i]+1][j]=1;
				}
				bx[i]++;
			} else {
				break;
			}
		}
		while(by[i]<=9999){
			nsum=(bx[i]-ax[i]+1)*(by[i]-ay[i]+1);
			rg int jud=1;
			for(rg int j=ax[i];j<=bx[i];j++){
				if(vis[j][by[i]+1]==1) jud=0;
			}
			if(!jud) break;
			rg double tmp1=(double)std::min(nsum,r[i])/(double)std::max(nsum,r[i]);
			rg double tmp2=(double)std::min(nsum+bx[i]-ax[i]+1,r[i])/(double)std::max(nsum+bx[i]-ax[i]+1,r[i]);
			if((1-tmp1*tmp1)*(1-tmp1*tmp1)>(1-tmp2*tmp2)*(1-tmp2*tmp2)){
				nsum+=bx[i]-ax[i]+1;
				for(rg int j=ax[i];j<=bx[i];j++){
					vis[j][by[i]+1]=1;
				}
				by[i]++;
			} else {
				break;
			}
		}
	}
	for(rg int i=1;i<=n;i++) printf("%d %d %d %d\n",ax[i],ay[i],bx[i],by[i]);
	return 0;
}

#include <cstdio>
using namespace std;
int n,m,k;
int c[102],d[102],a[102],b[102],ans;
bool vis[102];
void dfs(int x){
	if(x==k){
		int cnt=0;
		for(int i=0;i<m;++i){
			if(vis[a[i]]&&vis[b[i]])++cnt;
		}
		if(ans<cnt)ans=cnt;
	}else if(vis[c[x]]&&vis[d[x]]){
		dfs(x+1);
	}else{
		if(!vis[c[x]]){
			vis[c[x]]=true;
			dfs(x+1);
			vis[c[x]]=false;
		}
		if(!vis[d[x]]){
			vis[d[x]]=true;
			dfs(x+1);
			vis[d[x]]=false;
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;++i){
		scanf("%d%d",a+i,b+i);
	}
	scanf("%d",&k);
	for(int i=0;i<k;++i){
		scanf("%d%d",c+i,d+i);
	}
	dfs(0);
	printf("%d\n",ans);
	return 0;
}
