#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5, maxv = 1e6 + 17, mod = 1e9 + 7;
int main() {
  int T;
  cin >> T;
  while (T--) {
    string s;
    int n, l = 0, ans = 0, f = 0;
    cin >> n;
    cin >> s;
    for (char i : s) {
      if (i == 'A') {
        f = 1;
        if (l) ans = max(ans, l);
        l = 0;
      } else if (f)
        l++;
    }
    if (f) ans = max(ans, l);
    cout << ans << "\n";
  }
  return 0;
}
