package main import ( "bufio" "bytes" "fmt" "os" "regexp" "strconv" ) var sc = bufio.NewScanner(os.Stdin) func main() { sc.Split(bufio.ScanWords) t := nextInt() r := regexp.MustCompile(`W.*?G`) r2 := regexp.MustCompile(`G.*?R`) for i := 0; i < t; i++ { b := []byte(nextLine()) c := 0 for j := 0; j < 3; j++ { loc := r.FindIndex(b) if loc == nil { break } b[loc[0]] = 'A' base := loc[1] - 1 loc = r2.FindIndex(b[loc[1]-1:]) if loc == nil { break } b[loc[0]+base], b[loc[1]-1+base] = 'A', 'A' c++ } if bytes.Contains(b, []byte{'G'}) || bytes.Contains(b, []byte{'R'}) { fmt.Println("impossible") continue } if c < 1 { fmt.Println("impossible") continue } fmt.Println("possible") } } func nextLine() string { sc.Scan() return sc.Text() } func nextInt() int { i, _ := strconv.Atoi(nextLine()) return i }