#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int k;
    cin >> k;
    string s;
    cin >> s;
    int i;
    vector<int> v;
    for (i = 0; i < k; i++) {
      if (s[i] == 'A') {
        v.push_back(i);
      }
    }
    int l = v.size();
    if (l == 0) {
      cout << 0 << endl;
      continue;
    }
    int max = 0;
    for (i = 1; i < l; i++) {
      int x = v[i] - v[i - 1] - 1;
      if (x > max) {
        max = x;
      }
    }
    int z = k - v[l - 1] - 1;
    if (z > max) {
      max = z;
    }
    cout << max << endl;
  }
}
