#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000 + 7;
const int SS = 1 << 20;
const int INF = 1000 * 1000 * 1000 + 7;
int t[MAXN];
int n, m, q, k;
char other(char c) {
  if (c == 'R') return 'L';
  return 'R';
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    string s;
    cin >> n >> s;
    int i = 0;
    while (i < n && s[i] == s[0]) i++;
    for (int j = 0; j < i; j++) s += s[0];
    int res = 0;
    if (i == n) s[i] = other(s[i]), res++;
    n = s.size();
    for (; i < n; i++) {
      int rozm = 0;
      int j = i;
      while (j < n && s[j] == s[i]) j++, rozm++;
      res += rozm / 3;
      i = j - 1;
    }
    cout << res << '\n';
  }
  return 0;
}
