#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, i, j, k = 0, c = -1, l = 0, m = 0;
    cin >> n;
    string s;
    cin >> s;
    for (i = n - 1; i >= 0; i--) {
      if (s[i] == 'P') {
        c = i;
        break;
      }
    }
    for (i = c; i >= 0; i--) {
      if (s[i] == 'P') {
        l++;
      } else {
        k = max(l, k);
        l = 0;
        m = 1;
      }
    }
    if (m == 1) {
      cout << k << "\n";
    } else {
      cout << "0\n";
    }
  }
  return 0;
}
