package main import ( "bufio" "bytes" "fmt" "os" "strconv" ) var sc = bufio.NewScanner(os.Stdin) func main() { sc.Split(bufio.ScanWords) t := nextInt() ans := make([]byte, 0, 10000) imp, po := []byte("impossible\n"), []byte("possible\n") for i := 0; i < t; i++ { f := true b := []byte(nextLine()) r := bytes.LastIndexByte(b, 'R') for len(b)-1 == r { b[r] = 'D' g := bytes.LastIndexByte(b, 'G') if g == -1 { f = true break } b[g] = 'D' w := bytes.LastIndexByte(b[:g+1], 'W') if w == -1 { f = true break } r = bytes.LastIndexByte(b[:r], 'R') f = false if r == -1 { break } b = b[:r+1] } if f { ans = append(ans, imp...) continue } if bytes.LastIndexByte(b, 'G') != -1 || bytes.LastIndexByte(b, 'R') != -1 { ans = append(ans, imp...) continue } ans = append(ans, po...) } fmt.Println(string(ans)) } func nextLine() string { sc.Scan() return sc.Text() } func nextInt() int { i, _ := strconv.Atoi(nextLine()) return i }