#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string a;
    cin >> a;
    string last = a;
    for (long long i = 0; i <= n; ++i) {
      string s;
      s = a;
      for (long long k = 1; k < n; ++k) {
        if (a[k - 1] == 'A') {
          s[k] = 'A';
        }
      }
      a = s;
      if (a == last) {
        cout << i << "\n";
        break;
      }
      last = a;
    }
  }
}
