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