#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, i;
    int d = 0, c = 0;
    cin >> n;
    string s;
    cin >> s;
    for (i = n - 1; i >= 0; i--) {
      if (s[i] == 'P')
        c++;
      else {
        d = max(d, c);
        c = 0;
      }
    }
    cout << d << endl;
  }
  return 0;
}
