#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read_int()
{
char ch=getchar();
int x=0;
while(!isdigit(ch))
ch=getchar();
while(isdigit(ch))
{
x=x*10+ch-'0';
ch=getchar();
}
return x;
}
inline ll read_ll()
{
char ch=getchar();
ll x=0;
while(!isdigit(ch))
ch=getchar();
while(isdigit(ch))
{
x=x*10+ch-'0';
ch=getchar();
}
return x;
}
int n,m,q;
struct edge1
{
int x,y;
ll l;
}e1[100005],e2[10005];
int cnt1=0,cnt2=0;
struct edge
{
int to,nex;
ll l;
}e[10005];
int point[5005],cnt=0;
int father[5005],deep[5005];
int fa[10005][16];
ll dis[10005][16];
inline void add1(int x,int y,ll l)
{
e1[++cnt1].x=x;
e1[cnt1].y=y;
e1[cnt1].l=l;
}
inline void add2(int x,int y,ll l)
{
e2[++cnt2].x=x;
e2[cnt2].y=y;
e2[cnt2].l=l;
}
inline void add(int x,int y,ll l)
{
e[++cnt].to=y;
e[cnt].nex=point[x];
point[x]=cnt;
e[cnt].l=l;
}
inline int find(int x)
{
if(father[x]!=x) father[x]=find(father[x]);
return father[x];
}
inline bool cmp(edge1 x,edge1 y)
{
return x.l<y.l;
}
void Kruskal1()
{
int i;
sort(e1+1,e1+cnt1+1,cmp);
for(i=1;i<=n;i++)
father[i]=i;
for(i=1;i<=m;i++)
{
int f1=find(e1[i].x);
int f2=find(e1[i].y);
if(f1!=f2)
{
add(e1[i].x,e1[i].y,e1[i].l);
add(e1[i].y,e1[i].x,e1[i].l);
add2(e1[i].x,e1[i].y,e1[i].l);
father[f2]=f1;
}
}
}
void Kruskal2()
{
int i,len=cnt2;
sort(e2+1,e2+cnt2+1,cmp);
for(i=1;i<=n;i++)
father[i]=i;
cnt2=0;
for(i=1;i<=len;i++)
{
int f1=find(e2[i].x);
int f2=find(e2[i].y);
if(f1!=f2)
{
add(e2[i].x,e2[i].y,e2[i].l);
add(e2[i].y,e2[i].x,e2[i].l);
add2(e2[i].x,e2[i].y,e2[i].l);
father[f2]=f1;
}
}
}
void dfs(int u)
{
int i;
for(i=point[u];i;i=e[i].nex)
if(fa[u][0]!=e[i].to)
{
fa[e[i].to][0]=u;
dis[e[i].to][0]=e[i].l;
deep[e[i].to]=deep[u]+1;
dfs(e[i].to);
}
}
inline ll maxx(ll x,ll y)
{
if(x>y) return x;
else return y;
}
inline void init()
{
for(int j=1;(1<<j)<=n;j++)
for(int i=1;i<=n;i++)
{
fa[i][j]=fa[fa[i][j-1]][j-1];
dis[i][j]=maxx(dis[i][j-1],dis[fa[i][j-1]][j-1]);
}
}
ll get_lca_and_max(int x,int y)
{
int i;
ll ret=0;
if(deep[x]>deep[y]) swap(x,y);
int f=deep[y]-deep[x];
for(i=0;(1<<i)<=f;i++)
if(f&(1<<i))
y=fa[y][i],ret=maxx(ret,dis[y][i]);
if(x!=y)
{
for(i=(int)log2(n);i>=0;i--)
{
if(fa[x][i]!=fa[y][i])
{
ret=maxx(ret,dis[x][i]);
ret=maxx(ret,dis[y][i]);
x=fa[x][i];
y=fa[y][i];
}
}
ret=maxx(ret,dis[x][0]);
ret=maxx(ret,dis[y][0]);
}
return ret;
}
int main()
{
//freopen("game19.in","r",stdin);
//freopen("game.out","w",stdout);
int i,x,y,m1,m2,b1,b2;
string s;
long long z;
n=read_int(),m=read_int();
for(i=1;i<=m;i++)
{
x=read_int(),y=read_int(),z=read_ll();
add1(x,y,z);
}
Kruskal1();
dfs(1);
init();
q=read_int();
while(q--)
{
cin>>s;
if(s=="game")
{
m1=read_int(),m2=read_int();
b1=read_int(),b2=read_int();
if(get_lca_and_max(m1,m2)==get_lca_and_max(b1,b2))
printf("Baozika\n");
else
printf("madoka\n");
}
else
{
x=read_int(),y=read_int(),z=read_ll();
if(z<e2[cnt2].l)
{
memset(point,0,sizeof(point));
cnt=0;
add2(x,y,z);
Kruskal2();
dfs(1);
init();
}
}
}
return 0;
}