#include <bits/stdc++.h>
using namespace std;
long long int mm = 1000000007;
long long int pow1(long long int n, long long int k) {
  if (k == 0) return 1;
  if (k % 2 == 0) return (pow1((n % mm) * (n % mm), k / 2)) % mm;
  return ((n % mm) * (pow1((n % mm) * (n % mm), k / 2) % mm)) % mm;
}
void solve() {
  long long int n, c = 0, ans = 0;
  cin >> n;
  string s;
  cin >> s;
  for (long long int i = 0; i < n; i++) {
    if (s[i] == 'A') c++;
  }
  if (c == 0) {
    cout << 0 << endl;
    return;
  }
  c = 0;
  for (long long int i = n - 1; i >= 0; i--) {
    if (s[i] == 'A') {
      ans = max(c, ans);
      c = 0;
    } else
      c++;
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int q;
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
