#include <bits/stdc++.h>
using namespace std;
priority_queue<long long int, vector<long long int>, greater<long long int> >
    pq;
double startTime;
double getCurrentTime() {
  return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
bool isPrime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int power(long long int x, unsigned long long int y,
                    long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void outP(long long int idx) { cout << "Case #" << idx << ": "; }
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    long long int ans = 0;
    if (s == string(n, 'L') || s == string(n, 'R'))
      ans = (n + 2) / 3;
    else {
      long long int p = -1;
      for (long long int i = 1; i < n; i++) {
        if (s[i] != s[i - 1]) {
          p = i;
          break;
        }
      }
      for (long long int i = 1; i < n; i++) {
        long long int start = (p + i - 1) % n, cur = (p + i) % n;
        if (s[start] == s[cur]) {
          long long int j = i;
          while (j < n && s[start] == s[(p + j) % n]) j++;
          long long int len = j - i + 1;
          ans += len / 3;
          i = j;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
