#include <bits/stdc++.h>
using namespace std;
int check(string s, int n, char ck) {
  int ans = 0;
  int sm = 0;
  int fsm = -1;
  int lsm = -1;
  bool f = false;
  vector<int> sms;
  for (int i = 0; i < n; i++) {
    if (s[i] == ck) {
      sm++;
    } else {
      if (f) {
        fsm = sm;
        f = false;
      } else {
        sms.push_back(sm);
      }
      sm = 0;
    }
  }
  lsm = sm;
  if (sms.size()) {
    sms[0] += lsm;
  } else {
    sms.push_back(lsm);
    return (lsm + 2) / 3;
  }
  for (int i = 0; i < sms.size(); i++) {
    ans += (sms[i]) / 3;
  }
  return ans;
}
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  cout << check(s, n, 'R') + check(s, n, 'L') << '\n';
}
void querySolve() {
  int n;
  cin >> n;
  while (n--) {
    solve();
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  querySolve();
}
