using System; using System.Collections.Generic; using System.IO; using System.Text; 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(); Predicate deleteall = DeleteAll; Console.SetIn(new StreamReader(Console.OpenStandardInput(), new System.Text.ASCIIEncoding(), false, 1024)); /*Stream inputStream = Console.OpenStandardInput(); byte[] bytes = new byte[2048]; int outputLength;*/ for (int i = 0; i < lines; i++) { line.Add(Console.ReadLine()); /*outputLength = inputStream.Read(bytes, 0, 2048); line.Add(new string(Encoding.UTF8.GetChars(bytes, 0, outputLength)));*/ } 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.RemoveAll(deleteall); } } private static bool DeleteAll(byte b) { return true; } 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() { for (int i = 0; i < this.Count; i++) { if (this[i] == color_rg) { this[i] += color_w; return true; } } return true; } public bool Inspect() { for (int i = 0; i < this.Count; i++) { if (this[i] != color_rgw) { return false; } } return true; } } } }