#include <bits/stdc++.h>
using namespace std;
const int N=30+5;
int n;
bitset<N>a[N];
void gauss(){
int i=1,now=1;
for (;i<=n&&now<=n;i++,now++){
for (int j=i+1;j<=n;j++){
if (a[j][now]>a[i][now]){
swap(a[i],a[j]);
}
}
if (a[i][now]==0){
i--;continue;
}
for (int j=1;j<=n;j++){
if (i==j||a[j][now]==0)continue;
a[j]^=a[i];
if (a[j]==1){
printf("Oh,it's impossible~!!\n");
return ;
}
}
}
printf("%d\n",(1<<(n-i+1)));
return ;
}
int main(){
freopen ("switch.in","r",stdin);
freopen ("switch.out","w",stdout);
int T;
scanf("%d",&T);
for (int tt=1;tt<=T;tt++){
memset(a,0,sizeof(a));
scanf("%d",&n);
int t;
for (int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for (int i=1;i<=n;i++){
scanf("%d",&t);
a[i]^=t;a[i][i]=1;
}
int x,y;
while(scanf("%d%d",&x,&y)!=EOF){
if (x==0)break;
a[y][x]=1;
}
gauss();
}
return 0;
}