using System; using System.Collections.Generic; using System.IO; namespace Citybus { class Program { static void Main(string[] args) { bool possible; char[] charary; Tube TestTube = new Tube(); int lines = int.Parse(Console.ReadLine()); List line = new List(); //Console.SetIn(new StreamReader(Console.OpenStandardInput(8192))); for (int i = 0; i < lines; i++) { line.Add(Console.ReadLine()); } for (int i = 0; i < lines; i++) { possible = true; charary = line[i].ToCharArray(); for (int j = charary.Length - 1; j > -1 && possible; j--) { switch (charary[j]) { case 'R': TestTube.AddRed(); break; case 'G': possible = TestTube.AddGreen(); break; case 'W': possible = TestTube.AddWhite(); break; } } if( possible && TestTube.Inspect() ) { Console.WriteLine("possible"); } else { Console.WriteLine("impossible"); } TestTube.Clear(); } } private class Tube : List { const byte color_r = 1; const byte color_g = 2; const byte color_w = 4; const byte color_rg = 3; const byte color_rgw = 7; public void AddRed() { this.Add(color_r); } public bool AddGreen() { for(int i = 0; i < this.Count; i++) { if (this[i] == color_r) { this[i] += color_g; return true; } }; return false; } public bool AddWhite() { bool r = false; for (int i = 0; i < this.Count; i++) { if (this[i] == color_rg) { this[i] += color_w; return true; } if (this[i] == color_rgw) { r = true; } } return r; } public bool Inspect() { for (int i = 0; i < this.Count; i++) { if (this[i] != color_rgw) { return false; } } return true; } } } }