#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1e9 + 7;
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T> v) {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i > 0) {
      os << " ";
    }
    os << v[i];
  }
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<vector<T>> v) {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i > 0) {
      os << endl;
    }
    os << v[i];
  }
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    string s;
    cin >> n >> s;
    long long res = 0;
    for (int i = 0; i < (int)n; ++i) {
      if (s[i] == 'P') continue;
      int j = i + 1;
      while (j < n && s[j] == 'P') {
        j++;
      }
      long long len = j - i - 1;
      res = max(res, len);
      i = j - 1;
    }
    cout << res << endl;
  }
  return 0;
}
