#include <bits/stdc++.h>
using namespace std;
int64_t i, j, t, n, w, r;
char a[100];
int main() {
  cin >> t;
  for (i = 1; i <= t; i++) {
    cin >> n >> a;
    w = -1;
    r = 0;
    for (j = 0; j < n; j++) {
      if (a[j] == 'A') {
        w = 0;
      } else {
        if (w != -1) {
          w++;
          if (r < w) r = w;
        }
      }
    }
    cout << r << endl;
  }
}
