#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m = 0;
    cin >> n;
    string s;
    cin >> s;
    int x = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (s[i] == 'A') {
        m = max(m, x);
        x = 0;
      } else
        x++;
    }
    cout << m << endl;
  }
}
