#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    if (s.find("L") == string::npos || s.find("R") == string::npos) {
      ans = ceil(s.size() / 3.0);
    } else {
      int lenFirst = 0;
      char curr = s[0];
      int len = 1;
      for (int i = 1; i < n; i++) {
        if (s[i] == curr) {
          len++;
        } else {
          if (!lenFirst) lenFirst = len;
          ans += len / 3;
          len = 1;
          curr = s[i];
        }
      }
      if (s[0] == s[n - 1]) {
        ans -= lenFirst / 3;
        ans += (len + lenFirst) / 3;
      } else {
        ans += len / 3;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
