#include <bits/stdc++.h>
using namespace std;
long long int vis1[1000000];
long long int ara1[100005], ara2[100005];
map<long long int, long long int> vis;
map<long long int, long long int> str2;
priority_queue<long long int> pq;
vector<long long int> vec;
int main() {
  long long int a, b, c = 0, sum = 0, n;
  scanf("%lld", &n);
  for (long long int i = 1; i <= n; i++) {
    scanf("%lld", &a);
    long long int mx = 0;
    string str;
    cin >> str;
    c = -1;
    for (long long int i = 0; i < a; i++) {
      if (str[i] != 'A' && c != -1) {
        c++;
        if (c > mx) mx = c;
      } else if (str[i] == 'A')
        c = 0;
    }
    cout << mx << endl;
  }
  return 0;
}
