#include <bits/stdc++.h>
using namespace std;
int debug = 0;
int main() {
  if (!debug) ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int mx = 0, now = 0, nn = 0;
    for (int i = 0; i < n; ++i) {
      if (s[i] == 'A') {
        mx = max(mx, now);
        now = 0;
        nn = 1;
      } else {
        if (nn) {
          ++now;
        }
      }
    }
    mx = max(mx, now);
    cout << mx << '\n';
  }
  return 0;
}
