#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
int x,y;
}e[11],f[11];
void cal(node *p,int m,int &x0,int &x1,int &y0,int &y1,int &s)
{
int b,len;
x0=x1=y0=y1=s=0;
for(int i=0;i<m;++i)
{
b=(i+1)%m;
if(p[i].x==p[b].x)
{
len=abs(p[i].y-p[b].y);
if(len>x1) x0=x1,x1=len;
else x0=len;
s++;
}
else if(p[i].y==p[b].y)
{
len=abs(p[i].x-p[b].x);
if(len>y1) y0=y1,y1=len;
else y0=len;
s++;
}
}
}
bool judge()
{
int b,tmp[5],k,a;
for(int i=0;i<5;++i)
{
b=(i+1)%5;
if(f[i].x==f[b].x) tmp[i]=abs(f[i].y-f[b].y);
else if(f[i].y==f[b].y) tmp[i]=abs(f[i].x-f[b].x);
else k=i;
}
if(tmp[(k+1)%5]>tmp[(k+3)%5]) a=1;
else a=-1;
if(tmp[(k+2)%5]>tmp[(k+4)%5]) b=1;
else b=-1;
return a*b<0;
}
bool solve(int m1,int m2)
{
int x0,x1,y0,y1,X0,Y0,X1,Y1;
int xa,ya,xb,yb,sa,sb;
cal(e,m1,x0,x1,y0,y1,sa);
xa=x1-x0;
ya=y1-y0;
cal(f,m2,X0,X1,Y0,Y1,sb);
xb=X1-X0;
yb=Y1-Y0;
if(m1==4 && m2==4)
{
if(sa==4 && sb==4) return x0==X0 || x0==Y0 || y0==X0 || y0==Y0;
if(sa!=m1-1 || sb!=m2-1) return false;
int h0,h1,kx0,kx1,kd0,kd1;
if(!x0) h0=x1,kx0=y0,kd0=y1;
else h0=y1,kx0=x0,kd0=x1;
if(!X0) h1=X1,kx1=Y0,kd1=Y1;
else h1=Y1,kx1=X0,kd1=X1;
if(h0!=h1 || kx0+kd1!=kd0+kx1) return false;
if(xa==xb && ya==yb) return true;
if(xa==yb && ya==xb) return true;
return false;
}
else
{
if(sa!=m1-1 || sb!=m2-1 || sa>4 || sb>4) return false;
if(m1==4 && m2!=4) return false;
if(m2==5)
if((xa==xb && ya==yb)||(xa==yb && ya==xb)) return judge();
else return false;
else
{
if(xa==xb && ya==yb) return true;
if(xa==yb && ya==xb) return true;
return false;
}
}
}
int main()
{
int T,m1,m2;
scanf("%d",&T);
while(T--)
{
scanf("%d",&m1);
for(int i=0;i<m1;++i) scanf("%d%d",&e[i].x,&e[i].y);
scanf("%d",&m2);
for(int i=0;i<m2;++i) scanf("%d%d",&f[i].x,&f[i].y);
if(m1>m2) swap(m1,m2),swap(e,f);
puts(solve(m1,m2) ? "YES" : "NO");
}
return 0;
}