#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug &operator<<(const c &) {
    return *this;
  }
};
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    vector<string> p = {"RL", "RRL", "RRLL", "RLL"};
    long long n;
    cin >> n;
    string s;
    cin >> s;
    long long res = (long long)1e18;
    for (long long k = 0; k < 5; k++) {
      vector<long long> dp(n + 1, (long long)1e18);
      dp[0] = 0;
      for (long long i = 0; i < n; i++) {
        if (dp[i] == (long long)1e18) continue;
        for (string q : p) {
          long long j = q.size() + i;
          if (j <= n) {
            long long c = 0;
            for (long long r = 0; r < q.size(); r++) {
              c += (s[r + i] != q[r]);
            }
            dp[j] = min(dp[j], c + dp[i]);
          }
        }
      }
      res = min(res, dp[n]);
      s = s.substr(1, s.size() - 1) + s[0];
    }
    cout << res << "\n";
  }
  return 0;
}
