#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long mod) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
long long modInverse(long long a, long long m) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long binomial(long long n, long long k) {
  long long res = 1;
  if (k > n - k) k = n - k;
  for (long long i = 0; i < k; ++i) {
    res *= (n - i);
    res /= (i + 1);
  }
  return res;
}
const long long N = 1e5 + 9;
void doper() {}
int32_t main() {
  doper();
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    bool l = 0, r = 0;
    for (auto i : s) {
      if (i == 'L')
        l = 1;
      else
        r = 1;
    }
    long long ans = 0;
    if (!l or !r) {
      ans = ceil(n / 3.0);
    } else {
      vector<long long> v;
      for (long long i = 0; i < n;) {
        char c = s[i];
        long long j = i;
        while (s[j] == c) j++;
        v.push_back(j - i);
        i = j;
      }
      if (s[0] == s[n - 1]) {
        v[0] += v.back();
        v.pop_back();
      }
      for (auto i : v) ans += (i / 3);
    }
    cout << ans;
    cout << "\n";
    ;
  }
  return 0;
}
