#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
long long int powmod(long long int a, long long int b) {
  long long int res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int nxt() {
  int x;
  scanf("%d", &x);
  return x;
}
int main() {
  int tc = nxt();
  while (tc--) {
    int n = nxt();
    string s;
    cin >> s;
    int ans = 0, prev = -1;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'A')
        prev = i;
      else {
        if (prev != -1) ans = max(ans, i - prev);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
