#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int SZ = 55555;
string s;
void solve() {
  int k;
  cin >> k >> s;
  s += 'A';
  int l = -1, ans = 0;
  for (int i = 0; i <= k; ++i) {
    if (s[i] == 'A') {
      if (l >= 0) {
        ans = max(i - l - 1, ans);
      }
      l = i;
    }
  }
  cout << ans << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
