#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
class Solution {
 public:
  int solve(size_t n, string& s) {
    s.push_back(s[0]);
    s.push_back(s[1]);
    vector<string> strs = {"LL", "LR", "RL", "RR"};
    int dpLL, dpLR, dpRL, dpRR;
    vector<int*> ptrs = {&dpLL, &dpLR, &dpRL, &dpRR};
    int result = s.size();
    for (int i = 0; i < 4; ++i) {
      dpLL = s.size();
      dpLR = s.size();
      dpRL = s.size();
      dpRR = s.size();
      *ptrs[i] = 0;
      solve(s, dpLL, dpLR, dpRL, dpRR);
      result = min(result, *ptrs[i]);
    }
    return result;
  }
  void solve(string& s, int& dpLL, int& dpLR, int& dpRL, int& dpRR) {
    for (size_t i = 2; i < s.size(); ++i) {
      int dpLLnew = min({dpRL}) + (s[i] != 'L');
      int dpLRnew = min({dpLL, dpRL}) + (s[i] != 'R');
      int dpRLnew = min({dpLR, dpRR}) + (s[i] != 'L');
      int dpRRnew = min({dpLR}) + (s[i] != 'R');
      dpLL = dpLLnew;
      dpLR = dpLRnew;
      dpRL = dpRLnew;
      dpRR = dpRRnew;
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    size_t n;
    cin >> n;
    string s;
    cin >> s;
    auto result = Solution().solve(n, s);
    cout << result << endl;
  }
  return 0;
}
