#include <bits/stdc++.h>
using namespace std;
void fast_io() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int32_t main() {
  fast_io();
  long long t;
  cin >> t;
  while (t--) {
    long long n, Max = INT_MIN, count = 0, p = 0;
    cin >> n;
    string str;
    cin >> str;
    for (long long i = 0; i < n; i++) {
      if (str[i] == 'A') {
        p = 1;
        count = 0;
      } else if (p == 1) {
        count++;
        if (count > Max) Max = count;
      }
    }
    if (Max == INT_MIN)
      cout << "0"
           << "\n";
    else
      cout << Max << "\n";
  }
}
