#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
bool ok[1024000];
int A1[1024000],B1[1024000],A2[1024000],B2[1024000],a1,a2,b1,b2;
int main(){
	int Tc;scanf("%d",&Tc);
	for(int n,m;Tc--;){
		scanf("%d",&n);
		getchar();
		for(int i=0;i<n;++i){
			static	char tmp[1000];
			gets(tmp);
			for (int j=strlen(tmp)-1;j>=0;j--)
				if (tmp[j]==',') tmp[j] = ' ';
			istringstream in(tmp);
			in>> A1[i]>>B1[i]>>A2[i]>>B2[i];
		
		//	printf("%d,%d %d,%d\n",A1[i],B1[i],A2[i],B2[i]);
			ok[i]=false;
		}
		scanf("%d",&m);
		assert((long long)n*m<=1000000000);
		for(;m--;){
			scanf("%d,%d %d,%d",&a1,&b1,&a2,&b2);
		//	printf("%d,%d %d,%d\n",a1,b1,a2,b2);
			for(int i=0;i<n;++i)if(!ok[i]){
				if(a1<A2[i] || a2>A1[i])continue;
			//	if(a1 == 90 && A1[i]==90 ||a2 == -90 && A2[i]==-90 ){
			//		ok[i]=true;
			//		continue;
			//	}
				if(B1[i]<=B2[i]){
					if(b1<=b2){
						if(B1[i]>b2 || B2[i]<b1)continue;
					}else{
						if(b2<B1[i] && b1>B2[i])continue;
					}
				}else{
					if(b1<=b2){
						if(B1[i]>b2 && B2[i]<b1)continue;
					}
				}
				ok[i] = true;
			}
		}
		bool noout = true;
		for(int i=0;i<n;++i)if(ok[i])
			printf("%d,%d %d,%d\n",A1[i],B1[i],A2[i],B2[i]),noout=false;
		if(noout)puts("No data found.");
		if(Tc)puts("");
	}
	return 0;
}
