import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; import java.util.List; import java.util.Scanner; public class TownBus { public static void main(String[] args) { List input = new ArrayList<>(); try(Scanner s = new Scanner(System.in)){ int c = Integer.parseInt(s.nextLine()); //s.nextLine(); for(int i = 0; i < c ; i++){ String line = s.nextLine(); input.add(line); } } for(String line : input){ check(line); } } private static void check(String s){ Deque green = new ArrayDeque<>(); System.out.println(s); for(char light : s.toCharArray()){ switch(light){ case 'W': break; case 'G': green.push(light); break; case 'R': if(green.pollFirst() == null){ System.out.println("impossible"); return; } break; default: System.out.println("impossible"); return; } } if(green.isEmpty()){ System.out.println("possible"); }else{ System.out.println("impossible"); } } }