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