#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  long long int t, n, m, c, i;
  cin >> t;
  while (t--) {
    cin >> n >> s;
    bool flag = false;
    c = 0;
    m = 0;
    for (i = 0; i < n; i++) {
      if (s[i] == 'A') {
        flag = true;
        c = 0;
      } else if (flag == true)
        c++;
      m = max(m, c);
    }
    cout << m << endl;
  }
  return 0;
}
