#include <bits/stdc++.h>
using namespace std;
int arr[100009],arr1[100009];
int find_grp(int num)
{
while(num!=arr[num])
num=arr[num];
return num;
}
int main()
{
int t;
cin>>t;
while (t--)
{
int n,g;
cin>>n>>g;
int gen[g+1];
for (int i=1; i<=g; i++)
cin>>gen[i];
int q;
cin>>q;
memset(arr,0,sizeof(arr));
memset(arr1,0,sizeof(arr1));
while(q--)
{
int type;
cin>>type;
if (type==1)
{
char c;
cin>>c;
int id1,id2;
cin>>id1>>id2;
if (c=='c')
{
int num=find_grp(id1);
arr[id2]=num;
arr1[id2]=arr[num];
}
if (c=='g'){
arr[id2]=id2;
arr1[id2]=id1;
}
}
if (type==2)
{
int id;
cin>>id;
int num=find_grp(id);
if (num==0)
cout<<"Free\n";
else if (gen[arr1[num]]==0)
cout<<"Bhagat\n";
else
cout<<"Dukkar\n";
}
if (type==3)
{
int id;
cin>>id;
if (gen[id]==0)
gen[id]=1;
else
gen[id]=0;
//gen[id]=!gen[id];
}
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBhcnJbMTAwMDA5XSxhcnIxWzEwMDAwOV07CmludCBmaW5kX2dycChpbnQgbnVtKQp7Cgl3aGlsZShudW0hPWFycltudW1dKQoJCW51bT1hcnJbbnVtXTsKCXJldHVybiBudW07Cn0KaW50IG1haW4oKQp7CglpbnQgdDsKCWNpbj4+dDsKCXdoaWxlICh0LS0pCgl7CgkJaW50IG4sZzsKCQljaW4+Pm4+Pmc7CgkJaW50IGdlbltnKzFdOwoJCWZvciAoaW50IGk9MTsgaTw9ZzsgaSsrKQoJCQljaW4+PmdlbltpXTsKCQlpbnQgcTsKCQljaW4+PnE7CgkJbWVtc2V0KGFyciwwLHNpemVvZihhcnIpKTsKCQltZW1zZXQoYXJyMSwwLHNpemVvZihhcnIxKSk7CgkJd2hpbGUocS0tKQoJCXsKCQkJaW50IHR5cGU7CgkJCWNpbj4+dHlwZTsKCQ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