#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long double PI = acos(-1);
const long long N = 5e5 + 1;
void test_case() {
  long long n;
  string s;
  cin >> n >> s;
  vector<long long> vv;
  char curr = 'L';
  long long tt = 0;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == curr) {
      tt++;
    } else {
      if (tt) vv.push_back(tt);
      tt = 1;
      curr = s[i];
    }
  }
  vv.push_back(tt);
  if (vv.size() == 1) {
    cout << (vv[0] + 2) / 3 << '\n';
    return;
  }
  if (s[0] == curr) {
    for (int i = 1; i < vv.size() - 1; i++) {
      ans += vv[i] / 3;
    }
    ans += (vv[0] + vv.back()) / 3;
  } else {
    for (int i = 0; i < vv.size(); i++) {
      ans += vv[i] / 3;
    }
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tc = 1;
  cin >> tc;
  while (tc--) test_case();
  return 0;
}
