# Here your code ! def possible?(s) lines = [] s.chars.reverse.find {|c| if c == 'R' lines << 2 false elsif c == 'G' redpos = lines.find_index(2) lines[redpos] = 1 if redpos !redpos else wgpos = lines.find_index {|v| v < 2} lines[wgpos] = 0 if wgpos !wgpos end }.nil? end n = gets.to_i n.times do puts possible?(gets.chomp) ? "possible" : "impossible" end