#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
using ll = long long;
void solve() {
  string s;
  int a;
  cin >> a >> s;
  int sum = 0;
  vector<int> v;
  v.push_back(0);
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == 'P')
      sum++;
    else {
      v.push_back(sum);
      sum = 0;
    }
  }
  cout << *max_element(v.begin(), v.end()) << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
