#include <bits/stdc++.h>
const double pi = std::acos(-1);
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;
}
long long int spf[(long long int)1e7 + 2] = {0};
void siv() {
  spf[1] = 1;
  for (long long int i = 1; i < 1e7 + 2; i++) spf[i] = i;
  for (long long int i = 2; i < 1e7 + 2; i++) spf[i] = 2, i++;
  for (long long int i = 3; i * i < (long long int)1e7 + 2; i++) {
    if (spf[i] == i)
      for (long long int j = i * i; j < (long long int)1e7 + 2; j = j + i)
        if (spf[j] == j) spf[j] = i;
  }
}
int main() {
  long long int tc;
  cin >> tc;
  while (tc--) {
    long long int n;
    cin >> n;
    long long int arr[n];
    string s;
    cin >> s;
    string s1 = s;
    long long int i = 0;
    long long int kl = 0, kr = 0;
    deque<char> v1;
    s = s + "#";
    vector<pair<char, long long int>> v;
    for (long long int j = i; j < i + n + 1; j++) {
      if (s[j] == s[j + 1]) {
        if (s[j] == 'L')
          kl++;
        else if (s[j] == 'R')
          kr++;
      } else {
        if (s[j] == 'R')
          v.push_back({'R', ++kr});
        else if (s[j] == 'L') {
          v.push_back({'L', ++kl});
        }
        kl = 0, kr = 0;
      }
    }
    long long int ans = 0;
    long long int kj = 0;
    if (v.size() > 1) {
      if (v[0].first == v[v.size() - 1].first) {
        v[v.size() - 1].second = v[v.size() - 1].second + v[0].second;
        kj = 1;
      }
    }
    if (v.size() == 1) {
      if (v[0].second > 2) {
        ans = v[0].second / 3;
        if (v[0].second % 3) ans++;
      }
    }
    if (v.size() > 1)
      for (long long int j = kj; j < v.size(); j++) {
        if (v[j].second >= 3) {
          ans = ans + (v[j].second - 2) / 3;
          if ((v[j].second - 2) % 3) ans++;
        }
      }
    cout << ans << '\n';
  }
  return 0;
}
