#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long N = 5e5 + 100;
const double pi = 3.14159265358979323846264338327950288419716939937510;
void solve() {
  long long n;
  string s;
  cin >> n >> s;
  long long l = 0;
  while (l < n && s[l] == 'P') ++l;
  long long ans = 0, cur = 0;
  for (; l < n; ++l) {
    if (s[l] == 'P')
      ++cur;
    else
      cur = 0;
    ans = max(ans, cur);
  }
  cout << ans;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tt = 1;
  cin >> tt;
  while (tt--) {
    solve();
    cout << '\n';
  }
}
