#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int i, j, k, countt = 0, num = 0, large, c = 0, n, length;
  cin >> n;
  for (j = 0; j < n; j++) {
    cin >> length;
    cin >> s;
    while (c < length) {
      i = c;
      if (s[i] == 'A') {
        while (i < length - 1) {
          i++;
          if (s[i] == 'P') {
            countt++;
          } else {
            i--;
            break;
          }
        }
        if (num <= countt) {
          num = countt;
        }
      }
      countt = 0;
      c = i + 1;
    }
    if (num == 0) {
      cout << num << endl;
    } else {
      cout << num << endl;
    }
    num = 0;
    c = 0;
  }
  return 0;
}
