#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, Max = 0, cnt = 0, flag = false;
  cin >> n;
  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    if (c == 'A') {
      Max = max(cnt, Max);
      cnt = 0;
      flag = true;
    } else {
      if (flag) ++cnt;
    }
  }
  Max = max(Max, cnt);
  cout << Max << endl;
  return;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
