#include <bits/stdc++.h>
using namespace std;
template <class T>
void mini(T& l, T r) {
  l = min(l, r);
}
template <class T>
void maxi(T& l, T r) {
  l = max(l, r);
}
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
const int dx[] = {0, -1, 1, 0, -1, -1, 1, 1},
          dy[] = {-1, 0, 0, 1, -1, 1, -1, 1};
const int INF = 1e9;
const LL MOD = 1e9 + 7;
int t, T;
void Solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int res = 0;
  int pos = -1;
  for (int i = 0; i < n; i += 1) {
    if (s[i] == 'A') {
      if (pos != -1) res = max(res, i - pos - 1);
      pos = i;
    }
  }
  if (pos != -1) {
    res = max(res, n - 1 - pos);
  }
  cout << res << '\n';
  return;
}
void Prepare() { return; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> T;
  for (t = 1; t <= T; t++) {
    Solve();
  }
  return 0;
}
