#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int N;
long long A[200];
char S[202];
int Xs;
int Ys;
long long X[300];
long long Y[300];
void ord(int &sz, long long a[]){
  int bt, i;
  int ok = 0;
  for(bt=(63)-1;bt>=(0);bt--){
    int i;
    for(i=(ok);i<(sz);i++){
      if(a[i] & (1LL<<bt)){
        break;
      }
    }
    if(i==sz){
      continue;
    }
    if(i != ok){
      swap(a[i], a[ok]);
    }
    for(i=(ok+1);i<(sz);i++){
      if(a[i] & (1LL<<bt)){
        a[i] ^= a[ok];
      }
    }
    ok++;
  }
  ok = 0;
  for(i=(0);i<(sz);i++){
    if(a[i]){
      a[ok++] = a[i];
    }
  }
  sz = ok;
}
long long chk(int Xs, long long X[], long long y){
  int i;
  int bt = 62;
  for(i=(0);i<(Xs);i++){
    while(!(X[i] & (1LL<<bt))){
      bt--;
    }
    if(y & (1LL<<bt)){
      y ^= X[i];
    }
  }
  return y;
}
void attack(int Xs, long long X[], int &Ys, long long Y[]){
  int i;
  for(i=(0);i<(Ys);i++){
    Y[i] = chk(Xs, X, Y[i]);
  }
  ord(Ys, Y);
}
int main(){
  int hCmBdyQB;
  int V9aVTaxx = rd_int();
  for(hCmBdyQB=(0);hCmBdyQB<(V9aVTaxx);hCmBdyQB++){
    int i;
    rd(N);
    {
      int jZyWAPpY;
      for(jZyWAPpY=(0);jZyWAPpY<(N);jZyWAPpY++){
        rd(A[jZyWAPpY]);
      }
    }
    rd(S);
    Xs = Ys = 0;
    for(i=(N)-1;i>=(0);i--){
      if(S[i]=='0'){
        X[Xs++] = A[i];
        ord(Xs, X);
      }
      else{
        Y[Ys++] = A[i];
        attack(Xs, X, Ys, Y);
        if(Ys){
          wt_L(1);
          wt_L('\n');
          goto APIVbQlN;
        }
      }
    }
    if(Ys){
      wt_L(1);
      wt_L('\n');
    }
    else{
      wt_L(0);
      wt_L('\n');
    }
    APIVbQlN:;
  }
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int N;
// ll A[200];
// char S[202];
// 
// int Xs, Ys;
// ll X[300], Y[300];
// 
// void ord(int &sz, ll a[]){
//   int ok = 0;
//   rrep(bt,63){
//     rep(i,ok,sz) if(a[i] & (1LL<<bt)) break;
//     if(i==sz) continue;
//     if(i != ok) swap(a[i], a[ok]);
//     rep(i,ok+1,sz) if(a[i] & (1LL<<bt)) a[i] ^= a[ok];
//     ok++;
//   }
//   ok = 0;
//   rep(i,sz) if(a[i]) a[ok++] = a[i];
//   sz = ok;
// }
// 
// ll chk(int Xs, ll X[], ll y){
//   int bt = 62;
//   rep(i,Xs){
//     while(!(X[i] & (1LL<<bt))) bt--;
//     if(y & (1LL<<bt)) y ^= X[i];
//   }
//   return y;
// }
// 
// void attack(int Xs, ll X[], int &Ys, ll Y[]){
//   rep(i,Ys) Y[i] = chk(Xs, X, Y[i]);
//   ord(Ys, Y);
// }
// 
// {
//   REP(rd_int()){
//     rd(N,A(N),S);
//     Xs = Ys = 0;
//     rrep(i,N){
//       if(S[i]=='0'){
//         X[Xs++] = A[i];
//         ord(Xs, X);
//       } else {
//         Y[Ys++] = A[i];
//         attack(Xs, X, Ys, Y);
//         if(Ys) wt(1), break_continue;
// //        ord(Ys, Y);
// //        attack(Ys, Y, Xs, X);
//       }
// //      wt("X:", X(Xs));
// //      wt("Y:", Y(Ys));
//     }
//     wt(if[Ys, 1, 0]);
//   }
// }


Measured memory_bytes: 3844