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

int rec(int init, string circle, bool use, int n){
  int m = circle.size();
  bool f1 = true, f2 = true;
  for(int i=0;i<m;i++){
    if(circle[i]=='B')f1 = false;
    if(circle[i]=='G')f2 = false;
  }
  if(f1)return 0;
  if(f2)return m;

  int res = 0, rm = (init+n-1)%m;
  string tmp = circle;
  tmp.erase(tmp.begin() + rm);
  res = max(res, rec( rm%(m-1), tmp, use, n));

  if(!use){
    rm = (rm+1)%m;
    tmp = circle;
    tmp.erase(tmp.begin() + rm);
    res = max(res, rec( rm%(m-1), tmp, 1, n));
  }
  return res;
}

int main(){
  int T;
  cin >> T;
  while(T--){
    int n;
    string s;
    cin >> n >> s;
    cout << rec(0,s,0,n) << endl;
  }
}