#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    int ans = 0;
    cin >> n;
    string s;
    cin >> s;
    vector<int> v;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'A') {
        v.push_back(i + 1);
      }
    }
    if (v.size() == 0) {
      cout << 0 << endl;
      continue;
    }
    ans = n - v[v.size() - 1];
    for (int i = 0; i < v.size() - 1; i++) {
      ans = max(ans, v[i + 1] - v[i] - 1);
    }
    cout << ans << endl;
  }
}
