#include <bits/stdc++.h>
#define endl "\n"
#define INT long long int

using namespace std;

char infile[100], outfile[100];
char S[300000];
INT n, l, r, x, y;
int main() {
    ios::sync_with_stdio(false);
    INT T, n, i,j,A, a,I,p;
    cin >> T;
    for(I=6;I<=T;I++){
        sprintf(infile, ".%d.in", I);
        freopen(infile, "w", stdout);
        
        scanf("%d",&n);
        for(i=0;i<n;i++){
        	a = rand()%11;
        	if(a==10) S[i]='?';
        	else S[i]=a+'0';
		}
        printf("%d\n%s",n, S);    
		    
	    for(int i = 0 ; i < n ; i++ ){
	        if( S[i] == '?' ) {
	            if( i < n/2 ) x++;
	            else y++;
	            continue;
	        }
	        if( i < n/2 ) l += S[i]-'0';
	        else r += S[i]-'0';
    	}
        		
        sprintf(outfile, ".%d.out", I);
        freopen(outfile, "w", stdout);
        if( l+(x*4.5) == r+(y*4.5) ) printf("G");
    	else printf("S");
    }
}
