#include <bits/stdc++.h>
using namespace std;
int mem[200005][2][2][2][2], n;
char str[200005];
bool ara[200005];
int dp(int pos, bool f1, bool f2, bool f3, bool f4) {
  if (pos == n - 1) {
    int mn = 100000000;
    if ((!f1 && !f2) || (!f3 && !f4) || (!f2 && !f3))
      ;
    else
      mn = min(mn, (int)(ara[pos] != 0));
    if ((f1 && f2) || (f3 && f4) || (f2 && f3))
      ;
    else
      mn = min(mn, (int)(ara[pos] != 1));
    return mn;
  }
  if (mem[pos][f1][f2][f3][f4] != -1) return mem[pos][f1][f2][f3][f4];
  mem[pos][f1][f2][f3][f4] = 1000000009;
  if (!f1 && !f2)
    mem[pos][f1][f2][f3][f4] = (ara[pos] != 1) + dp(pos + 1, f2, 1, f3, f4);
  else if (f1 && f2)
    mem[pos][f1][f2][f3][f4] = (ara[pos] != 0) + dp(pos + 1, f2, 0, f3, f4);
  else
    mem[pos][f1][f2][f3][f4] =
        min((ara[pos] != 1) + dp(pos + 1, f2, 1, f3, f4),
            (ara[pos] != 0) + dp(pos + 1, f2, 0, f3, f4));
  return mem[pos][f1][f2][f3][f4];
}
int main() {
  int ts;
  scanf("%d", &ts);
  while (ts--) {
    scanf("%d %s", &n, str);
    for (int i = 0; i < n; i++) {
      if (str[i] == 'L')
        ara[i] = 0;
      else
        ara[i] = 1;
    }
    for (int i = 0; i <= n + 2; i++)
      for (int j = 0; j < 2; j++)
        for (int k = 0; k < 2; k++)
          for (int l = 0; l < 2; l++)
            for (int m = 0; m < 2; m++) mem[i][j][k][l][m] = -1;
    int res = 2 * n;
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++)
        res = min(res, (ara[0] != i) + (ara[1] != j) + dp(2, i, j, i, j));
    printf("%d\n", res);
  }
  return 0;
}
