#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmin(T& a, const T b){ if(b < a){ a = b; return true; } return false; } template inline bool chmax(T& a, const T b){ if(a < b){ a = b; return true; } return false; } template inline bool bitUP(const T state, const unsigned int k) { return (state >> k) & 0b01; } inline bool isIn(int x, int y, int H, int W){return 0 <= x and x < H and 0 <= y and y < W;} inline auto isInTheGrid(const int H, const int W){ return std::bind(isIn, std::placeholders::_1, std::placeholders::_2, H, W); } template std::vector make_vector(const unsigned int n, const element_t& init_value){ return std::vector(n, init_value); } template auto make_vector(const unsigned int n, const unsigned int m, Tp... args){ return std::vector(m, args...))>(n, make_vector(m, args...)); } namespace MyInputAndOutput{ // 入力関係 (cin) class user_input{ private: static constexpr unsigned int sizeOfAscii = 128; bool isBlankChar[sizeOfAscii]; /* < definition of getchar > reference MacOS : https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getchar.3.html Windows : https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getchar-nolock-getwchar-nolock?view=vs-2019 Linux : https://linux.die.net/man/3/unlocked_stdio Ubuntu : http://manpages.ubuntu.com/manpages/trusty/man3/getchar_unlocked.3posix.html */ #if defined(__APPLE__) #define DAGGER_GETCHAR_UNLOCKED_DAGGER getchar_unlocked #elif defined(_WIN32) || defined(_WIN64) #define DAGGER_GETCHAR_UNLOCKED_DAGGER _getchar_nolock #elif defined(__linux) #if _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE || _BSD_SOURCE || _SVID_SOURCE #define DAGGER_GETCHAR_UNLOCKED_DAGGER getchar_unlocked #else #define DAGGER_GETCHAR_UNLOCKED_DAGGER getchar #endif #else #define DAGGER_GETCHAR_UNLOCKED_DAGGER getchar #endif // 符号あり整数を getchar で読み込んで構成する (もし, 0 ~ 9 以外の文字が含まれると困る) template inline void charToInteger(Tp& val) const { val = 0; int c; while(true){ c = DAGGER_GETCHAR_UNLOCKED_DAGGER(); if(c == EOF) return; if('-' or (not isBlankChar[c])) break; } if(c == '-'){ while(true){ c = DAGGER_GETCHAR_UNLOCKED_DAGGER(); if(c < '0' or c > '9') break; val = 10 * val + c - '0'; } val = -val; } else{ if(c < '0' or c > '9') return; do{ val = 10 * val + c - '0'; c = DAGGER_GETCHAR_UNLOCKED_DAGGER(); } while('0' <= c and c <= '9'); } } // 符号なし整数を getchar で読み込んで構成する (もし, 符号付きだとバグる) template inline void charToUnsignedInteger(Tp& val) const { val = 0; int c; while(true){ c = DAGGER_GETCHAR_UNLOCKED_DAGGER(); if(c == EOF) return; if(not isBlankChar[c]) break; } if(c < '0' or c > '9') return; do{ val = 10 * val + c - '0'; c = DAGGER_GETCHAR_UNLOCKED_DAGGER(); } while(not (c == EOF or isBlankChar[c])); } public: constexpr user_input(void) : isBlankChar(){ for(unsigned int i = 0; i < sizeOfAscii; ++i) isBlankChar[i] = false; isBlankChar[int('\n')] = true; isBlankChar[int('\t')] = true; isBlankChar[int(' ')] = true; isBlankChar[int('\v')] = true; } inline const user_input& operator >> (int& int_arg) const { charToInteger(int_arg); return *this; } inline const user_input& operator >> (long long int& llint_arg) const { charToInteger(llint_arg); return *this; } inline const user_input& operator >> (unsigned int& uint_arg) const { charToUnsignedInteger(uint_arg); return *this; } inline const user_input& operator >> (unsigned long long int& ullint_arg) const { charToUnsignedInteger(ullint_arg); return *this; } inline const user_input& operator >> (unsigned long& ulint_arg) const { charToUnsignedInteger(ulint_arg); return *this; } inline const user_input& operator >> (float& float_arg) const { scanf("%f", &float_arg); return *this; } inline const user_input& operator >> (double& double_arg) const { scanf("%lf", &double_arg); return *this; } inline const user_input& operator >> (long double& ldouble_arg) const { scanf("%Lf", &ldouble_arg); return *this; } inline const user_input& operator >> (char* str_arg) const { scanf("%s", str_arg); return *this; } inline const user_input& operator >> (char& char_arg) const { do{ if((char_arg = DAGGER_GETCHAR_UNLOCKED_DAGGER()) == EOF) return *this; } while(isBlankChar[int(char_arg)]); return *this; } inline const user_input& operator >> (std::string& str_arg) const { str_arg.erase(); int c; while(true){ c = DAGGER_GETCHAR_UNLOCKED_DAGGER(); if(c == EOF) return *this; if(not isBlankChar[c]) break; } constexpr unsigned int buffer_size = 128; char buffer_input[buffer_size]; unsigned int buffer_length = 0; do{ buffer_input[buffer_length++] = c; if(buffer_length == buffer_size){ buffer_length = 0; str_arg.append(buffer_input, buffer_size); } c = DAGGER_GETCHAR_UNLOCKED_DAGGER(); } while(c != EOF and (not isBlankChar[c]) ); str_arg.append(buffer_input, buffer_length); return *this; } template inline const user_input& operator >>(std::pair& pair_arg) const{ (*this) >> pair_arg.first >> pair_arg.second; return *this; } template inline const user_input& operator >>(std::vector& vec) const { for(T& ele : vec) (*this) >> ele; return *this; } // getchar の define の解除 #undef DAGGER_GETCHAR_UNLOCKED_DAGGER }; constexpr user_input cin; void ends(void) {putchar('\0'); } void endl(void) {putchar('\n'); fflush(stdout);} void flush(void) {fflush(stdout);} constexpr char eol = '\n'; // 出力関係 (cout) class user_output{ public: constexpr user_output(void){} inline const user_output& operator << (const int int_arg) const{ printf("%d", int_arg); return *this; } inline const user_output& operator << (const unsigned int uint_arg) const{ printf("%u", uint_arg); return *this; } inline const user_output& operator << (const long long int llint_arg) const { printf("%lld", llint_arg); return *this; } inline const user_output& operator << (const unsigned long long int ullint_arg) const { printf("%llu", ullint_arg); return *this; } inline const user_output& operator << (const unsigned long ulint_arg) const { printf("%lu", ulint_arg); return *this; } inline const user_output& operator << (const float flt_arg) const { printf("%.16f", flt_arg); return *this; } inline const user_output& operator << (const double ld_arg) const { printf("%.16lf", ld_arg); return *this; } inline const user_output& operator << (const long double ld_arg) const { printf("%.16Lf", ld_arg); return *this; } inline const user_output& operator << (const char char_arg) const { putchar(char_arg); return *this; } inline const user_output& operator << (const unsigned char uchar_arg) const { putchar(uchar_arg); return *this; } inline const user_output& operator << (const char* str_arg) const { fputs(str_arg, stdout); return *this; } inline const user_output& operator << (const std::string& str_arg) const { fputs(str_arg.c_str(), stdout); return *this; } inline const user_output& operator << (void(* const func_arg)(void)) const { func_arg(); return *this; } template inline const user_output& operator <<(const std::pair& pair_arg) const{ (*this) << pair_arg.first << ' ' << pair_arg.second; return *this; } template inline const user_output& operator << (const std::vector& vec) const { const size_t size_of_vec = vec.size(); if(size_of_vec <= 0) return *this; (*this) << vec[0]; for(size_t index = 1; index < size_of_vec; ++index) (*this) << ' ' << vec[index]; return *this; } }; constexpr user_output cout; // その他出力関数 template void binary_output(const Integer value, const unsigned int length = 64){ char out[length + 1]; for(unsigned int i = 0, j = length - 1; i < length; ++i, --j) out[j] = ((value >> i) & 1) ? '1' : '0'; out[length] = '\0'; puts(out); } template void print(InputType first, InputType last, const char separate_c = ' ', const char end_c = '\n'){ InputType it = first; while(true){ MyInputAndOutput::cout << *it; if(++it == last){MyInputAndOutput::cout << end_c; return;} MyInputAndOutput::cout << separate_c; } } }; namespace MIO = MyInputAndOutput; // z-algorithm template std::vector z_algorithm(const T &str) { const size_t n = str.size(); std::vector resOfCP(n); resOfCP[0] = n; int i = 1, j = 0; while (i < n) { while (i + j < n and str[j] == str[i + j]) ++j; resOfCP[i] = j; if (j == 0) { ++i; continue;} int k = 1; while (i + k < n and k + resOfCP[k] < j) resOfCP[i + k] = resOfCP[k], ++k; i += k; j -= k; } return resOfCP; } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // グリッド上の縦横移動 constexpr std::array, 4> dxdy = { { {1, 0}, {-1, 0}, {0, 1}, {0, -1} } }; // 型エイリアス using unint = unsigned int; using lli = long long int; using ulli = unsigned long long int; using pii = std::pair; #define REP(i, n) for(int i = 0; i < (n); ++i) // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ using MIO::cin; using MIO::cout; using MIO::eol; constexpr unsigned int MAX_S = 1000; char S[MAX_S + 10]; void solve(void){ unsigned int n; cin >> n >> S; unsigned int makereach = 0; for(unsigned int i = 0; i + 2 < n; ++i){ unsigned int p = 0, q = 0; if(S[i] == 'o') ++p; else if(S[i] == '-') ++q; if(S[i + 1] == 'o') ++p; else if(S[i + 1] == '-') ++q; if(S[i + 2] == 'o') ++p; else if(S[i + 2] == '-') ++q; if(p == 3 or (p == 2 and q == 1)){ cout << "O\n"; return ; } if(p == 1 and q == 2){ if(S[i] == '-'){ if((i > 0 and S[i - 1] != 'x') and (i + 1 < n and S[i + 1] != 'x')){ cout << "O\n"; return ; } } } } unsigned int idx = 0; while(idx < n){ if(S[idx] != 'o'){ idx++; continue; } unsigned int cnt = 1; while(idx + cnt < n){ if(S[idx + cnt] == '-') cnt++; else break; } const unsigned int lst = idx + cnt; if(lst < n and S[lst] == 'o'){ if(cnt % 2 == 0){ cout << "O\n"; return; } else if( (idx > 0 and S[idx - 1] == '-') or (lst + 1 < n and S[lst + 1] == '-')){ cout << "O\n"; return ; } } idx += cnt; } cout << "X\n"; } int main(void){ unsigned int Q; cin >> Q; while(Q--) solve(); return 0; }