win3 = set([ "ooo", "oo-", "o-o", "-oo", ]) win4 = set([ "--o-", "-o--", ]) win5 = set([ "o---o", ]) def RunLengthEncoding(S): res = [] N = len(S) i = 0 while i < N: cnt = 1 while i < N - 1 and S[i] == S[i + 1]: cnt += 1 i += 1 res.append((S[i], cnt)) i += 1 return res def game(N, S): for i in range(N - 2): sss = S[i: i + 3] if sss in win3: return True for i in range(N - 3): ssss = S[i:i+4] if ssss in win4: return True RLE = RunLengthEncoding(S) M = len(RLE) for i in range(M - 2): k, v = RLE[i] if k == "o": kc, vc = RLE[i+1] if kc == "-" and vc % 2 == 1 and RLE[i+2][0] == "o": return True return False if __name__ == "__main__": T = int(input()) ans = [] for _ in range(T): _, S = input().split() N = len(S) if game(N, S): ans.append("O") else: ans.append("X") print(*ans, sep="\n")