#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9 + 5;
const long long ooll = 1e18 + 5;
const int MOD = 998244353;
const int N = 1e6 + 5;
void solve() {
  int n, i;
  string s;
  cin >> n;
  cin >> s;
  bool fin = false;
  int ans = 0;
  while (!fin) {
    bool change = false;
    for (i = n - 2; i >= 0; i--)
      if (s[i] == 'A') {
        if (s[i + 1] != 'A') {
          s[i + 1] = 'A';
          change = true;
        }
      }
    if (!change) {
      fin = true;
    } else
      ans++;
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
