program main implicit none integer::T,i character*1000::S read *,T do i=1,T read *,S call analyze(S) end do contains subroutine analyze(S) integer::j,len,w,g,r,keitou character*1000::S len = LEN_TRIM(S) w = 0 g = 0 r = 0 do j=1,len if(S(j:j).eq.'R') then r = r + 1 if(r.gt.g.or.r.gt.w) then print '(a)',"impossible" return end if else if(S(j:j).eq.'G') then g = g + 1 if(g.gt.w) then print '(a)',"impossible" return end if else w = w + 1 end if end do if(g.ne.r) then print '(a)',"impossible" return end if w = 0 g = 0 r = 0 do j=len,1,-1 if(S(j:j).eq.'R') then r = r + 1 else if(S(j:j).eq.'G') then g = g + 1 if(r.eq.0) then print '(a)',"impossible" return end if else w = w + 1 if(r.eq.0.or.g.eq.0) then print '(a)',"impossible" return end if end if end do print '(a)',"possible" end subroutine analyze end program main