#include <bits/stdc++.h>
const long long mod = 1000000007;
const double eps = 1e-9;
const double pi = acos(-1.0);
using namespace std;
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int a = 0;
  int cnt = 0;
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == 'P') {
      cnt++;
    } else {
      a = max(a, cnt);
      cnt = 0;
    }
  }
  cout << a << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    solve();
  }
}
