#include <bits/stdc++.h>
using namespace std;
int tc, n, i, f, p, mx;
char st[101];
int main() {
  cin >> tc;
  while (tc--) {
    cin >> n;
    for (i = 0; i < n; i++) cin >> st[i];
    f = -1;
    for (i = 0; i < n; i++) {
      if (st[i] == 'A') {
        f = i;
        break;
      }
    }
    if (f == -1)
      cout << "0" << endl;
    else {
      p = 0, mx = 0;
      for (i = f + 1; i < n; i++) {
        if (st[i] == 'P') p++;
        if (st[i] == 'A' || i == n - 1) {
          if (p > mx) mx = p;
          p = 0;
        }
      }
      cout << mx << endl;
    }
  }
  return 0;
}
