m=%w(ooo oo- -oo o-o -o-- --o- o---o) gets.to_i.times{ n,s=gets.split puts m.any?{|t|s[t]}??O:?X}