#include<bits/stdc++.h>
#define MAXN 1010
using namespace std;
class Roadblock{
public:
int xx,yy;//行,列
int time;//时间
};
const int fx[4]={0,0,1,-1};
const int fy[4]={1,-1,0,0};
int T,n;
int x[MAXN],y[MAXN];
bool a[MAXN][MAXN];
bool visit[MAXN][MAXN];
bool flag;
Roadblock fx1,fx2;
queue<Roadblock>q;
void BFS(int h,int l,int t)//行,列,时间
{
fx1.xx=h,fx1.yy=l,fx1.time=t;
q.push(fx1);
while(!q.empty())
{
fx1=q.front();
q.pop();
if(fx1.xx==n&&fx1.yy==n)
{
flag=1;
break;
}
a[x[fx1.time-1]][y[fx1.time-1]]=1;
for(int i=0;i<4;i++)
{
int dx=fx1.xx+fx[i];
int dy=fx1.yy+fy[i];
if(dx>=1&&dx<=n&&dy>=1&&dy<=n)
{
fx2.xx=dx,fx2.yy=dy,fx2.time=fx1.time+1;
visit[dx][dy]=1;
q.push(fx2);
}
}
}
}
int main()
{
cin>>T;
while(T--)
{
cin>>n;
memset(a,0,sizeof(a));
memset(visit,0,sizeof(visit));
flag=0;
visit[1][1]=1;
for(int i=1;i<=2*n-2;i++)
cin>>x[i]>>y[i];
BFS(1,1,0);
if(flag==1) cout<<"Yes\n";
else cout<<"No\n";
}
return 0;
}
我MAXN即使开110还是有2个MLE