#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int mx = 0;
    int tmp = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (s[i] == 'P') {
        tmp++;
      } else {
        mx = max(mx, tmp);
        tmp = 0;
      }
    }
    cout << mx << endl;
  }
}
