#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    long long int dis = 0;
    long long int last = INT_MAX;
    for (long long int i = 0; i < n; i++) {
      if (s[i] == 'A') {
        dis = max(dis, i - last - 1);
        last = i;
      }
    }
    dis = max(dis, n - 1 - last);
    cout << dis << endl;
  }
}
