#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define ALL(v) v.begin(),v.end()
#define sz(v) (ll)v.size()
const ll INF = 1e18;
// const ll MOD = 998244353; 
// const ll MOD = 1000000007;
ll dx[] = {1, 0, -1, 0};
ll dy[] = {0, 1, 0, -1};
const double PI = acos(-1.0);

//--------------------------------------------------
//--------------------------------------------------

int main(){
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);

    ll n; cin >> n;
    string s;
    cin >> s;

    vector<ll> f(400100), g(400100);
    ll san = 1;
    g[0] = 1;
    for(int i = 1; i <= 400000; i++){
        ll pos = i;
        while(pos % 3 == 0) {pos /= 3; f[i]++;}
        g[i] = pos%3;
    }
    for(ll i = 1; i <= 400000; i++) {
        f[i] += f[i-1];
        g[i] = (g[i]*g[i-1])%3;
    }
    // cout << "f : ";
    // for(ll i = 0; i < 10; i++) {
    //     cout << f[i] << " \n"[i==9];
    // }
    // cout << "g : ";
    // for(ll i = 0; i < 10; i++) {
    //     cout << g[i] << " \n"[i==9];
    // }

    // BWR
    // 012

    for(ll i = 0; i < n; i++) {
        if(s[i]=='B') s[i] = '0';
        else if(s[i]=='W') s[i] = '1';
        else if(s[i]=='R') s[i] = '2';
    }

    ll ans = 0;
    ll N = n-1;
    ll r;

    for(ll i = 0; i < n; i++) {
        r = i;
        ll p;
        if(f[N] > f[r] + f[N-r]) {
            p = 0;
        }else{
            if(g[N]==1&&g[r]*g[N-r]==1) p = 1;
            else if(g[N]==1&&g[r]*g[N-r]==2) p = 2;
            else if(g[N]==1&&g[r]*g[N-r]==4) p = 1;
            else if(g[N]==2&&g[r]*g[N-r]==1) p = 2;
            else if(g[N]==2&&g[r]*g[N-r]==2) p = 1;
            else if(g[N]==2&&g[r]*g[N-r]==4) p = 2;
       }
        ans = (ans + (s[i]-'0') * p) % 3;
    }
    if(n%2==0) ans = (3-ans)%3;

    char ret;
    if(ans == 0) ret = 'B';
    else if(ans == 1) ret = 'W';
    else ret = 'R';

    cout << ret << endl;

    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

// size(x), rbegin(x), rend(x) need C++17
#define sz(x) int((x).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dbg(x) cout << "[" << #x << "]: " << x << endl;
#define forn(i,n) for(int i=0; i < n;i++)

using ll = long long;
using db = long double; //pode ser double

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>; 
using vs = vector<string>;
using vpi = vector<pi>;
using vpl = vector<pl>; 
using vpd = vector<pd>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 2e5 + 5;
const int MOD = 1e9+7; //998244353;
const int INF = 0x3f3f3f3f;
const ll INF64 = ll(4e18) + 5;
const db EPS = 1e-9;
const db PI = acos((db)-1);


bool perm(vi &p, int n){
	bool certo = true;

	forn(i,n){
		if(p[i] != i) certo = false;
	}

	return certo;
}


void solve(){
	int n;
	cin >> n;
	vi p(n);
	
	forn(i,n){
		cin >> p[i];
		p[i] -= 1;
	}

	vi ans;
	int at = 0;
	for(int i = n-1; i >= 3; i--){
		
		//colocando i em seu devido lugar
		//achando onde esta i
		int pos_i = -1;
		for(int j = 0; j <= i; j++){
			if(p[j] == i) pos_i = j;
		}
		if(pos_i == i) continue;

		if(pos_i%2 != at%2){
			if(at%2 == 0){
				swap(p[0], p[1]);
				at++;
				ans.pb(0);
				if(p[0] == i){
					swap(p[1], p[2]);
					at++;
					ans.pb(1);
					pos_i = 0;
				}
			}else{
				swap(p[1], p[2]);
				at++;
				ans.pb(1);
				if(p[1] == i){
					swap(p[2], p[3]);
					at++;
					ans.pb(2);
					pos_i = 1;
				}
			}

		}
		//agora posso comecar a mover o i para direita
		for(int j = pos_i; j < i; j++){
			ans.pb(j);
			at++;
			swap(p[j], p[j+1]);
		}
		
	}

	
	//neste momento tenho um de tamanho 3
	if(n >= 3){

		if(p[2] != 2){
			//se 2 nao esta certo
			if(p[1] == 2 && at%2 == 1){
				swap(p[1], p[2]);
				at++;
				ans.pb(1);
			}else if(p[1] == 2 && at%2 == 0){
				swap(p[0], p[1]);
				at++;
				ans.pb(0);

				swap(p[1],p[2]);
				at++;
				ans.pb(1);

				swap(p[0],p[1]);
				at++;
				ans.pb(0);

				swap(p[1], p[2]);
				at++;
				ans.pb(1);
			}else{
				if(at%2 == 1){
					swap(p[1], p[2]);
					at++;
					ans.pb(1);
				}

				swap(p[0],p[1]);
				at++;
				ans.pb(0);

				swap(p[1], p[2]);
				at++;
				ans.pb(1);

			}
		}else{
			if(at%2 == 1 && p[0] == 1){
				swap(p[1], p[2]);
				at++;
				ans.pb(1);
				
				swap(p[0],p[1]);
				at++;
				ans.pb(0);

				swap(p[1], p[2]);
				at++;
				ans.pb(1);
				
				swap(p[0],p[1]);
				at++;
				ans.pb(0);

				swap(p[1], p[2]);
				at++;
				ans.pb(1);


			}
		}
	}	

	if(p[0] == 1){
		swap(p[0],p[1]);
		at++;
		ans.pb(0);
	}	

	cout << ans.size() << '\n';

	if(ans.size() > 0){


		for(int i = 0; i < ans.size(); i++){
			cout << ans[i] +1 << " ";
		}cout << '\n';
	}
}

int main(){

    ios::sync_with_stdio(false); cin.tie(NULL);

    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }

    return 0;
}

/*
PRESTA ATENCAO!!!!

NAO FIQUE PRESO EM UMA ABORDAGEM
A SUA INTUICAO PODE ESTAR ERRADA - TENTE OUTRAS COISAS
LIMPOU TUDO PARA O PROXIMO CASO?
caso especial? n == 1 

*/
