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