#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long k;
    cin >> k;
    string s;
    cin >> s;
    s = s + "A";
    long long len = 0, cur = 0;
    long long i = 0;
    while (i <= k && s[i] == 'P') i++;
    for (; i <= k; i++) {
      if (s[i] == 'A') {
        if (cur > len) len = cur;
        cur = 0;
      } else
        cur++;
    }
    cout << len << "\n";
  }
}
