#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const long long INF64 = 1e18;
template <typename T>
string to_string(const vector<T> &v) {
  string ret = "<";
  for (auto it : v) ret += to_string(it) + ", ";
  ret.pop_back();
  ret.pop_back();
  ret += ">";
  return ret;
}
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug_print() { cerr << endl; }
template <typename T, typename... U>
void debug_print(T t, U... u) {
  cerr << " " << to_string(t);
  debug_print(u...);
}
const int N = 2e5 + 5;
long long dp[N];
long long n;
string s, p;
long long solve_2(long long x) { return (s[x] != 'L') + (s[x - 1] != 'R'); }
long long solve_3(long long x) { return (s[x - 2] != 'R') + (s[x] != 'L'); }
long long solve_4(long long x) {
  return (s[x - 3] != 'R') + (s[x - 2] != 'R') + (s[x - 1] != 'L') +
         (s[x] != 'L');
}
long long solve() {
  dp[0] = INF;
  dp[1] = solve_2(1);
  dp[2] = solve_3(2);
  for (int i = 3; i < n; i++) {
    dp[i] = min(solve_2(i) + dp[i - 2], solve_3(i) + dp[i - 3]);
    if (i > 2) dp[i] = min(dp[i], solve_4(i) + (i - 4 < 0 ? 0 : dp[i - 4]));
  }
  return dp[n - 1];
}
long long work() {
  long long ans = solve();
  s = s.substr(1, n - 1) + s[0];
  ans = min(ans, solve());
  s = s.substr(1, n - 1) + s[0];
  ans = min(ans, solve());
  s = s.substr(1, n - 1) + s[0];
  ans = min(ans, solve());
  s = s.substr(1, n - 1) + s[0];
  ans = min(ans, solve());
  return ans;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> s;
    long long ans = work();
    cout << ans << endl;
  }
  return 0;
}
