#include<stdio.h>
#include<string.h>
int main(){
int n,k,i,j;
char str[55];
scanf("%d",&k);
while(k--){
int p=1,q=1,count=0,sum=0;
scanf("%d",&n);
int a[55],b[55]; //储存每行X的个数
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(i=1;i<=n;i++){
scanf("%s",&str);
for(j=0;j<(strlen(str));j++){
if(str[j]=='X')
{
a[p]++;
}
}p++;
}
for(i=1;i<=n;i++){
scanf("%s",&str);
for(j=0;j<strlen(str);j++){
if(str[j]=='X')
{
b[q]++;
}
}q++;
}
for(i=1;i<=n;i++){
count<b[i]+a[i];
count=b[i]+a[i];
printf("%d",count);
}
for(i=1;i<=n;i++){
sum+=count-a[i]-b[i];
}
printf("%d\n",sum);
}
}
#include<string.h>
int main(){
int n,k,i,j;
char str[55];
scanf("%d",&k);
while(k--){
int p=1,q=1,count=0,sum=0;
scanf("%d",&n);
int a[55],b[55]; //储存每行X的个数
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(i=1;i<=n;i++){
scanf("%s",&str);
for(j=0;j<(strlen(str));j++){
if(str[j]=='X')
{
a[p]++;
}
}p++;
}
for(i=1;i<=n;i++){
scanf("%s",&str);
for(j=0;j<strlen(str);j++){
if(str[j]=='X')
{
b[q]++;
}
}q++;
}
for(i=1;i<=n;i++){
count<b[i]+a[i];
count=b[i]+a[i];
printf("%d",count);
}
for(i=1;i<=n;i++){
sum+=count-a[i]-b[i];
}
printf("%d\n",sum);
}
}