#include <bits/stdc++.h>
using namespace std;
int main() {
  int tt;
  cin >> tt;
  while (tt--) {
    int n, a, b, i;
    cin >> n;
    string s;
    cin >> s;
    s.push_back('A');
    int cnt = 0;
    int mx = 0;
    bool flag = false;
    for (i = 0; i < (int)s.size(); i++) {
      if (s[i] == 'A') flag = true;
      if (flag) {
        if (s[i] == 'A') {
          mx = max(mx, cnt);
          cnt = 0;
        } else
          cnt++;
      }
    }
    cout << mx << "\n";
  }
  return 0;
}
