#include <bits/stdc++.h>
using namespace std;
int const N = 2e5 + 10, INF = 1e9 + 10;
long long t, n, k, a[N], b[N];
string s;
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> s;
    int flg1 = 1, flg2 = 1;
    for (int i = 0; i < n; ++i) {
      if (s[i] == 'R') flg1 = 0;
      if (s[i] == 'L') flg2 = 0;
    }
    if (flg1 || flg2) {
      printf("%d\n", (n + 2) / 3);
      continue;
    }
    long long res = 0;
    string ss = s;
    if (ss[0] == ss[n - 1]) {
      int l = 1;
      while (ss[l] == ss[l - 1] && l < n) {
        l++;
      }
      int r = n - 2;
      while (ss[r] == ss[r + 1] && r >= 0) r--;
      res += (l + n - r - 1) / 3;
      int len = 1;
      for (int i = l + 1; i <= r; ++i) {
        if (ss[i] == ss[i - 1]) {
          len++;
        } else {
          res += (len / 3);
          len = 1;
        }
      }
      res += (len / 3);
      cout << res << endl;
    } else {
      int len = 1;
      int l = 0, r = n - 1;
      for (int i = l + 1; i <= r; ++i) {
        if (ss[i] == ss[i - 1]) {
          len++;
        } else {
          res += (len / 3);
          len = 1;
        }
      }
      res += (len / 3);
      cout << res << endl;
    }
  }
  return 0;
}
