#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  string s;
  cin >> n >> s;
  int ans = n;
  vector<string> validni{"RL", "RRL", "RRLL", "RLL"};
  for (int rot = 0; rot < 4; ++rot) {
    s = s.substr(1) + s[0];
    vector<int> dp(n + 1, n);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
      for (auto st : validni) {
        if (i + 1 - (int)(st).size() < 0) continue;
        int raz = 0;
        for (int j = 0; j < (int)(st).size(); ++j)
          raz += (s[i + 1 - (int)(st).size() + j] != st[j]);
        dp[i + 1] = min(dp[i + 1], dp[i + 1 - (int)(st).size()] + raz);
      }
    }
    ans = min(ans, dp[n]);
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
}
