#include<stdio.h>
long long MIN(long long a,long long b){return a<b?a:b;}
int main(){
  int t;
  scanf("%d",&t);
  while(t--){
    long long n,a[210],d[210],b[210],r=0,i,j,x;
    scanf("%lld",&n);
    for(i=0;i<n;i++)scanf("%lld",&d[i]);
    for(i=0;i<n;i++)scanf("%1lld",&a[i]);
    for(i=n;i--;){
      x=d[i];
      for(j=0;j<r;j++)x=MIN(x,x^b[j]);
      if(x){
	if(a[i])goto NEXT;
	else  b[r++]=x;
      }
    }
    printf("0\n");
    continue;
  NEXT:;
    printf("1\n");
  }
  return 0;
}
  
