#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, l;
  cin >> n;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> l;
    cin >> s;
    int ans = 0;
    bool lol = false;
    int tmp = 0;
    for (int j = 0; j < l; j++) {
      if (s[j] == 'A') {
        lol = true;
        if (tmp > ans) ans = tmp;
        tmp = 0;
      } else {
        if (lol) {
          tmp++;
        }
      }
    }
    if (tmp > ans) ans = tmp;
    cout << ans << "\n";
  }
  return 0;
}
