#include <bits/stdc++.h>
using namespace std;
int q, a, mx, l;
char arc;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> q;
  while (q--) {
    cin >> a;
    bool tor = 0, kke = 0;
    mx = l = 0;
    for (int i = 0; i < a; i++) {
      cin >> arc;
      if (arc == 'A') {
        kke = 1;
        if (tor) {
          l = 0;
        }
      } else {
        tor = 1;
        if (kke) l++;
      }
      mx = max(mx, l);
    }
    cout << mx << endl;
  }
}
