int main(){
int t;
sca(t);
while(t--){
int a[20];
memset(a,0,sizeof(a));
int flag;
for(int i=1;i<=16;i++){
sca(a[i]);
if(!a[i]) flag = i /4 + (i%4!=0);
}
int abs = 0;
for(int i=1;i<=16;i++){
if(a[i]==0) continue;
for(int j=i+1;j<=16;j++){
if(a[j]==0) continue;
if(a[i]>a[j]) abs++;
}
}
if(flag%2==0&&abs%2==0 || flag%2==1&&abs%2==1) prs("Yes");
else prs("No");
}
}