package main import ( "bufio" "fmt" "os" "strconv" ) func getScanner(fp *os.File) *bufio.Scanner { scanner := bufio.NewScanner(fp) scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) return scanner } func getNextString(scanner *bufio.Scanner) string { scanner.Scan() return scanner.Text() } func getNextInt(scanner *bufio.Scanner) int { i, _ := strconv.Atoi(getNextString(scanner)) return i } func getNextInt64(scanner *bufio.Scanner) int64 { i, _ := strconv.ParseInt(getNextString(scanner), 10, 64) return i } func getNextUint64(scanner *bufio.Scanner) uint64 { i, _ := strconv.ParseUint(getNextString(scanner), 10, 64) return i } func getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout cnt := 0 if os.Getenv("MASPY") == "ますピ" { fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT")) cnt = 0 } if os.Getenv("MASPYPY") == "ますピッピ" { wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10")) } scanner := getScanner(fp) writer := bufio.NewWriter(wfp) solve(scanner, writer) for i := 0; i < cnt; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } writer.Flush() } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { t := getNextInt(scanner) for i := 0; i < t; i++ { n := getNextInt(scanner) s := getNextString(scanner) if firstWin(n, s) { fmt.Fprintln(writer, "O") continue } fmt.Fprintln(writer, "X") } } func firstWin(n int, s string) bool { wins := [5]string{ "--o-", "-o--", "-oo", "oo-", "ooo", } for i := 0; i < n; i++ { for _, w := range wins { if i+len(w) > n { continue } if s[i:i+len(w)] == w { return true } } } l := -1 for r := 0; r < n; r++ { if s[r] == '-' { continue } if l >= 0 { if s[l] == 'o' && s[r] == 'o' && (r-l) > 1 && (r-l)%2 == 0 { return true } } l = r } return false }