#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const long long mod = 1e9 + 7;
int n, T;
char ch[maxn];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%s", &n, ch + 1);
    int flag = 0, cnt = 0, ans = 0;
    for (int i = 1; i <= n; i++) {
      if (ch[i] == 'A') {
        flag = 1;
        cnt = 0;
      } else if (flag) {
        cnt++;
        ans = max(ans, cnt);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
