#include <bits/stdc++.h>
using namespace std;
long long n, m, ar[200010], a, b, c, d, f[210][210][210], er[2000], t, ans,
    gr[2000], ans1, k;
string s, s1;
bool boo;
char ch;
map<int, int> Map;
vector<int> vt[2];
int main() {
  cin >> t;
  while (t--) {
    vt[0].clear();
    vt[1].clear();
    ans1 = 0;
    cin >> n;
    cin >> s;
    ans = 1;
    bool cr = (s[0] == 'L');
    for (int i = 1; i < n; i++) {
      if (s[i] == s[i - 1]) {
        ans++;
      }
      if (s[i] != s[i - 1]) {
        vt[cr].push_back(ans);
        ans = 1;
        cr = 1 - cr;
      }
    }
    vt[cr].push_back(ans);
    if (vt[cr].size() == 1 && vt[1 - cr].size() == 0) {
      if (n % 3 == 0) {
        cout << n / 3 << '\n';
        continue;
      }
      cout << n / 3 + 1 << '\n';
      continue;
    }
    if (s[0] == s[n - 1] && vt[cr].size() > 1) {
      ans1 += (vt[cr][0] + vt[cr][vt[cr].size() - 1]) / 3;
      for (int i = 1; i < vt[cr].size() - 1; i++) {
        ans1 += vt[cr][i] / 3;
      }
      for (int i = 0; i < vt[1 - cr].size(); i++) {
        ans1 += vt[1 - cr][i] / 3;
      }
      cout << ans1 << '\n';
      continue;
    }
    for (int i = 0; i < vt[0].size(); i++) {
      ans1 += vt[0][i] / 3;
    }
    for (int i = 0; i < vt[1].size(); i++) {
      ans1 += vt[1][i] / 3;
    }
    cout << ans1 << '\n';
  }
}
