roumeideclown @ 2025-01-11 14:55:38
rt.
#include<bits/stdc++.h>
// #pragma G++ optimize(2)
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using pii=pair<int,int>;
#define fi first
#define se second
constexpr int N=35;
int n,st[N],ed[N];
bitset<N> a[N];
void solve() {
cin>>n;
for(int i=1;i<=n;i++) cin>>st[i];
for(int i=1;i<=n;i++) cin>>ed[i];
for(int i=1;i<=n;i++)
for(int j=1;j<=n+1;j++)
a[i][j]=0;
int x,y;
while(cin>>x>>y&&x&&y) a[x][y]=1;
for(int i=1;i<=n;i++) a[i][i]=1,a[i][n+1]=st[i]^ed[i];
int curr=1;
for(int j=1;j<=n;j++) {
int p;
for(p=curr;p<=n&&!a[p][j];p++);
if(p==n+1) continue;
if(p!=curr) swap(a[curr],a[p]);
for(int i=1;i<=n;i++)
if(i!=curr&&a[i][j]) a[i]^=a[curr];
curr++;
}
int cnt=0;
for(int i=1;i<=n;i++) {
if(!a[i][i]) {
if(a[i][n+1]) {cout<<"Oh,it's impossible~!!\n";return;}
cnt++;
}
}
cout<<(1<<cnt)<<"\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t;cin>>t;
while(t--) solve();
return 0;
}