#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int k = s.size();
    int count = 0;
    int max = 0;
    for (int i = k - 1; i >= 0; i--) {
      if (s.at(i) == 'P') {
        count++;
      } else if (s.at(i) == 'A') {
        if (count > max) {
          max = count;
        }
        count = 0;
      }
    }
    int ans = 0;
    if (max == k) {
      ans = 0;
    } else {
      ans = max;
    }
    cout << ans << endl;
  }
}
