#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% T = int(readline()) query = readlines() # %% def solve(q): w_min = 0 w_max = 0 g = 0 for a in q.rstrip().decode(): if a == 'W': w_min = 1 w_max += 1 elif a == 'G': if not w_max: return False w_min = 0 w_max -= 1 g += 1 else: if not g: return False g -= 1 return w_min == 0 and g == 0 # %% answers = ('possible' if solve(q) else 'impossible' for q in query) print('\n'.join(answers))