#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int i = -1, res = 0;
    string s;
    cin >> s;
    for (int j = 0; j < n; j++) {
      if (s[j] == 'A') {
        i = j;
      } else {
        if (i != -1) res = max(res, j - i);
      }
    }
    cout << res << "\n";
  }
  return 0;
}
