#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using lld = long double;
using l64 = int64_t;
const ll MOD = 1000000007;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tc;
  string ss;
  int n;
  cin >> tc;
  while (tc--) {
    cin >> n;
    cin >> ss;
    int maxi = 0;
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      if (ss[i] == 'A') {
        for (int j = i + 1; j < n; j++) {
          if (ss[j] == 'P')
            cnt++;
          else
            break;
        }
        maxi = max(maxi, cnt);
      }
    }
    cout << maxi << '\n';
  }
  return 0;
}
