#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
char s[N];
int f[N], ans, n;
int cost(int x, int y) { return (s[x] != 'R') + (s[y] != 'L'); }
int cost(int x) {
  return (s[x] != 'R') + (s[x + 1] != 'R') + (s[x + 2] != 'L') +
         (s[x + 3] != 'L');
}
void dp() {
  f[0] = 0;
  f[1] = 0x3f3f3f3f;
  for (int i = 2; i <= n; i++) {
    f[i] = 0x3f3f3f3f;
    if (i >= 2) f[i] = min(f[i], f[i - 2] + cost(i - 1, i));
    if (i >= 3) f[i] = min(f[i], f[i - 3] + cost(i - 2, i));
    if (i >= 4) f[i] = min(f[i], f[i - 4] + cost(i - 3));
  }
  ans = min(ans, f[n]);
}
void change() {
  char c = s[1];
  for (int i = 1; i < n; i++) s[i] = s[i + 1];
  s[n] = c;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    scanf("%s", s + 1);
    ans = 0x3f3f3f3f;
    for (int i = 0; i < 4; i++) {
      dp();
      change();
    }
    printf("%d\n", ans);
  }
  return 0;
}
