#include <bits/stdc++.h>
const int N = 2000000 + 5;
const int INF = 0x3f3f3f3f;
const int MAXINT = 2147483647;
const int mod = 1000000007;
const long long MAXLONG = 9223372036854775807;
using namespace std;
template <class T>
inline bool read(T &ret) {
  char c;
  int sgn;
  if (static_cast<void>(c = getchar()), c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (static_cast<void>(c = getchar()), c >= '0' && c <= '9')
    ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
template <class T>
inline void write(T x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
void slove(int quetion_num) {
  while (quetion_num--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int num = 0, ans = 0;
    int pos = 0;
    for (int j = 0; j < n; ++j) {
      if (s[j] == 'A') {
        pos = j;
        break;
      }
    }
    for (int i = pos; i < n; ++i) {
      if (s[i] == 'A')
        ans = max(ans, num), num = 0;
      else
        num++;
    }
    if (pos == 0 && s[pos] != 'A') num = 0;
    cout << max(ans, num) << endl;
  }
}
int main() {
  int num = 1;
  cin >> num;
  slove(num);
  return 0;
}
