#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, i, j, l = -1, r = -1, ans = 0, lc = 0, rc = 0;
    cin >> n;
    string s;
    cin >> s;
    for (i = 0; i < n && (l == -1 || r == -1); i++) {
      if (s[i] == 'L') {
        lc++;
        if (l == -1) l = i;
      } else if (s[i] == 'R') {
        rc++;
        if (r == -1) r = i;
      }
    }
    if (rc == n || lc == n) {
      ans = n / 3;
      if (n % 3 != 0) ans++;
    } else {
      ans = 0;
      int st = max(l, r);
      i = st;
      lc = 0;
      rc = 0;
      int c = 0;
      while (c < n) {
        lc = 0;
        rc = 0;
        while (c < n && s[(c + st) % n] == 'R') {
          rc++;
          c++;
        }
        ans += rc / 3;
        while (c < n && s[(c + st) % n] == 'L') {
          lc++;
          c++;
        }
        ans += lc / 3;
      }
    }
    cout << ans << "\n";
  }
}
