#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int dig=60;
#define N 233
inline ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int T,n;
ll a[N];
char s[N];
struct Basis{
	ll d[64];
	void clear(){
		memset(d,0,sizeof(d));
	}
	void Insert(ll x){
		for(int i=dig;i>=0;--i){
			if((x>>i)&1){
				if(d[i]){
					x^=d[i];
				}
				else{
					d[i]=x;
					return;
				}
			}
		}
	}
	bool check(ll x){
		for(int i=dig;i>=0;--i){
			if((x>>i)&1){
				if(!d[i])return false;
				x^=d[i];
			}
		}
		return true;
	}
}B;
int Solve(){
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
	}
	scanf("%s",s+1);
	B.clear();
	for(int i=n;i>=1;--i){
		if(s[i]=='0'){
			B.Insert(a[i]);
		}
		else{
			if(!B.check(a[i]))return 1;
		}
	}
	return 0;
}
int main(){
	T=read();
	while(T--){
		printf("%d\n",Solve());
	}
	return 0;
}


#include <iostream>
using namespace std;
int main(){
  int n,p,i,m,a=0,I;
  int box[100]={};
  while(1){
    cin>>n>>p;
    a=0;
    if(n==0&&p==0) break;
    else{
      while(1){

	for(i=0;i<n;i++){
	  m=i;
	 
	  if(p>0){
	    box[m]+=1;
	    p-=1;
	  }
	  else if(p==0){
	    for(I=0;I<n;I++){
	      if(box[I]==0) a++;
	    }
	    if(a==n-1) {
	      break;
	    }
	    else {
	      p=box[m];
	      box[m]=0;
	      a=0;
	    }
	  }
	}
	if(a==n-1) break;
      }
      if(m-1<0){
	m=n;
      }
      cout<<m-1<<endl;
          } 
    for(i=0;i<n;i++){
      box[i]=0;
    }
  }
  return 0;
}