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