#include <bits/stdc++.h>
using namespace std;
long long q, n, i, j, ans, c;
string s;
bool f;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> q;
  while (q--) {
    cin >> n;
    cin >> s;
    c = s.size() - 1;
    f = true;
    for (i = 0; i <= s.size() - 1; i++) {
      if (s[i] != 'A') f = false;
    }
    if (f) {
      cout << "0" << '\n';
      continue;
    }
    ans = 0;
    for (i = s.size() - 1; i >= 0; i--) {
      if (s[i] == 'A') {
        ans = max(ans, c - i);
        c = i - 1;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
