#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 5;
int t;
int n;
string s;
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> s;
    int t1 = -1000;
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'P')
        t1++;
      else
        t1 = 0;
      ans = max(ans, t1);
    }
    cout << ans << endl;
  }
}
