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