#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000000 + 7;
long long int power(long long int x, long long int y, long long int md) {
  long long int res = 1;
  x = x % md;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % md;
    y = y >> 1;
    x = (x * x) % md;
  }
  return res;
}
long long int m_mul(long long int a, long long int b) {
  a = a % mod;
  b = b % mod;
  return (a * b + mod) % mod;
}
long long int m_add(long long int a, long long int b) {
  a = a % mod;
  b = b % mod;
  return (a + b + mod) % mod;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, i;
    cin >> n;
    string a;
    cin >> a;
    long long int b[n];
    for (i = 0; i < n; i++) {
      if (a[(i - 1 + n) % n] == 'L' && a[(i + 1 + n) % n] == 'R') {
        b[i] = 1;
      } else if (a[i] == 'L' && a[(i - 1 + n) % n] == 'R') {
        b[i] = 1;
      } else if (a[i] == 'R' && a[(i + 1 + n) % n] == 'L') {
        b[i] = 1;
      } else {
        b[i] = 0;
      }
    }
    long long int c = 0;
    for (i = 0; i < n; i++) {
      if (b[i] == 1)
        break;
      else
        c++;
    }
    long long int cc = 0;
    for (i = n - 1; i >= 0; i--) {
      if (b[i] == 1)
        break;
      else
        cc++;
    }
    if (c == n) {
      long long int p = n / 3;
      if (p * 3 < n) p++;
      cout << p << '\n';
      continue;
    }
    long long int ans = 0;
    long long int k = 0;
    for (i = c; i <= n - cc - 1; i++) {
      if (b[i] == 1) {
        long long int p = k / 3;
        if (p * 3 < k && k != 0) p++;
        ans = ans + p;
        k = 0;
      } else {
        k++;
      }
    }
    long long int pp = (c + cc) / 3;
    if (pp * 3 < (c + cc) && (c + cc) != 0) pp++;
    ans = ans + pp;
    cout << ans << '\n';
  }
  return 0;
}
