#include <bits/stdc++.h>
using namespace std;
int t;
vector<int> out;
void get(int n, bool a[]) {
  bool change = true;
  int min = 0;
  while (change) {
    change = false;
    for (int i = 0; i < n - 1; i++) {
      if (a[i] && !a[i + 1]) {
        a[i + 1] = true;
        change = true;
        i++;
      }
    }
    min++;
  }
  out.push_back(min - 1);
}
int main() {
  cin >> t;
  while (t > 0) {
    bool arr[108];
    int num;
    string s;
    cin >> num >> s;
    for (int i = 0; i < num; i++)
      if (s[i] == 'P')
        arr[i] = false;
      else
        arr[i] = true;
    get(num, arr);
    t--;
  }
  for (int val : out) cout << val << endl;
  return 0;
}
