#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)2e5;
int dp[MAXN + 1][2][2];
int main() {
  int t, i;
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> t;
  while (t--) {
    int n;
    string str;
    cin >> n >> str;
    str = " " + str;
    for (i = 1; i <= n; i++) {
      if (str[i] == 'L')
        str[i] = 0;
      else
        str[i] = 1;
    }
    const int INF = 1e9;
    auto ok = [&](int t, int a, int b) -> bool {
      return t + 1 - b == 2 || t + 1 - b == 0 || (t == 1 && a == 0) ||
             (b == 0 && a == 1);
    };
    int ans = INF;
    for (int t1 = 0; t1 < 2; t1++) {
      for (int t2 = 0; t2 < 2; t2++) {
        for (i = 1; i <= n; i++) {
          for (int a = 0; a < 2; a++) {
            for (int b = 0; b < 2; b++) {
              dp[i][a][b] = INF;
            }
          }
        }
        for (int a = 0; a < 2; a++) {
          if (ok(t1, t2, a)) dp[2][t2][a] = (str[1] != t2) + (str[2] != a);
        }
        for (i = 2; i < n; i++) {
          for (int a = 0; a < 2; a++) {
            for (int b = 0; b < 2; b++) {
              if (dp[i][a][b] == INF) continue;
              for (int c = 0; c < 2; c++) {
                if (ok(a, b, c))
                  dp[i + 1][b][c] =
                      min(dp[i + 1][b][c], dp[i][a][b] + (str[i + 1] != c));
              }
            }
          }
        }
        for (int a = 0; a < 2; a++) {
          if (ok(a, t1, t2)) ans = min(ans, dp[n][a][t1]);
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
