#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int T = 1, n, m;
  string str;
  cin >> T;
  while (T--) {
    long long int p = 0, q = 0, tmp = 0, sum = 0, count = 0;
    int flag = 0;
    cin >> n;
    cin >> str;
    for (int i = 0; i < n; i++) {
      if (str[i] == 'A') flag = 1;
      while (flag == 1 && i < n && str[i] == 'P') {
        i++;
        count++;
      }
      if (count > p) {
        p = count;
      }
      count = 0;
    }
    cout << p << "\n";
  }
  return 0;
}
