#include <bits/stdc++.h>
using namespace std;
const long long M = 998244353;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string second;
    cin >> second;
    string ss = "JGEC";
    int c = 0;
    for (int i = 0; i < n - 4; i++) {
      if (second.substr(i, 4) == ss) c++;
    }
    cout << c << endl;
  }
}
