#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int M;
  cin>>M;
  while(M--){
    int L; cin>>L;
    string s; cin>>s;
    //cout<<s<<endl;
    int N = s.size();
    int ans = 0;
    for(int i = 0; i < N; i++){
      int round = 0;
      int idx = 0;
      bool exist[200];
      REP(j, N)exist[j] = true;
      while(true){
        bool BG[2] = {};
        REP(j, N)if(exist[j]){
          BG[(s[j]=='B')?0:1] = true;
        }
        if(!BG[0] || !BG[1]) break;

        int sec = (L - 1) % (N - round);
        if(round == i) sec = L % (N - round);
        //cout<<sec<<" ";
        while(sec){
          do{
            idx = (idx + 1) % N;
          }while(!exist[idx]);
          sec--;
        }
        exist[idx] = false;
        do{
          idx = (idx + 1) % N;
        }while(!exist[idx]);
        /*
        REP(i, N){
          if(exist[i]) cout<<s[i];
          else cout<<"*";
        }
        cout<<endl;
        */
        round ++;
      }
      int countB = 0;
      REP(i, N) if(exist[i] && s[i] == 'B') countB++;
      //cout<<countB<<endl;
      ans = max(ans, countB);
    }
    cout<<ans<<endl;
  }
  return 0;
}