#include<stdio.h>
#include<string.h>
#define N 10
char s[N][N][N]={{"***","* *","* *","* *","***"},{" *"," *"," *"," *"," *"},{"***"," *","***","* ","***"},{"***"," *","***"," *","***"},{"* *","* *","***"," *"," *"},{"***","* ","***"," *","***"},
{"***","* ","***","* *","***"},{"***"," *"," *"," *"," *"},{"***","* *","***","* *","***"},{"***","* *","***"," *","***"}};
int main() {
int i,j,k,len,sum,co,cl,flag,jj,kk,f;
char ss[6][100];
char st[6][100];
while(gets(ss[1])) {
sum=0;
for(i=2;i<=5;i++)
gets(ss[i]);
len=strlen(ss[1]);
flag=0;
for(i=0;i<len;i+=4) {
co=0;
for(j=1;j<=5;j++) {
cl=0;
for(k=i;k<i+3&&k<strlen(ss[j]);k++)
st[co][cl++]=ss[j][k];
for(f=cl;f<3;f++)//有可能提前换行,不足补零
st[co][cl++]=' ';
st[co++][cl]=0;
}
for(jj=0;jj<10;jj++) {
for(kk=0;kk<5;kk++) {
if(strcmp(st[kk],s[jj][kk])!=0)
break;
}
if(kk==5)
break;
}
if(jj==10) {
flag=1;
break;
}
sum=sum*10+jj;
}
if(flag||sum%6!=0)printf("BOOM!!
");
else
printf("BEER!!
");
}
return 0;
}