#include <bits/stdc++.h>
using namespace std;
string good[] = {"RL", "RLL", "RRL", "RRLL"};
const long long N = 4;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tt;
  cin >> tt;
  while (tt--) {
    string s;
    long long n;
    cin >> n >> s;
    long long ans = INT_MAX;
    for (long long turn = 0; turn < 4; turn++) {
      string a(n, '_');
      for (long long i = 0; i < n; ++i) a[i] = s[(i + turn) % n];
      long long dp[n + 2];
      for (long long i = 0; i <= n; ++i) dp[i] = INT_MAX;
      dp[0] = 0;
      for (long long i = 1; i <= n; ++i) {
        long long minm = INT_MAX;
        for (long long j = 0; j < N; ++j) {
          long long cost = 0;
          if (good[j].length() > i) continue;
          for (long long k = (long long)good[j].length() - 1; k >= 0; --k) {
            if (a[i - k - 1] != good[j][k]) cost++;
          }
          long long total = cost;
          total += dp[i - (long long)good[j].length()];
          minm = min(minm, total);
        }
        dp[i] = minm;
      }
      ans = min(ans, dp[n]);
    }
    cout << ans << "\n";
  }
  return 0;
}
