#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n;
string str;
int to[N], good[N], vis[N], deg[N];
int dp[N];
int call(int x) {
  if (x <= 1) return 0;
  if (x <= 3) return 1;
  if (dp[x] != -1) return dp[x];
  int f = x - 2;
  return dp[x] = 1 + call(f / 2) + call(f - f / 2);
}
int com(int x) {
  if (x <= 1) return 0;
  if (x == 2) return 1;
  int d = x / 3;
  if (x % 3 == 2) d++;
  return d;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  memset(dp, -1, sizeof(dp));
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i <= n; i++) to[i] = good[i] = deg[i] = vis[i] = 0;
    cin >> str;
    set<char> st;
    for (char ch : str) st.insert(ch);
    if (st.size() == 1) {
      cout << com(n - 2) + 1 << "\n";
      continue;
    }
    for (int i = 0; i < n; i++) {
      if (str[i] == 'L') {
        to[i] = (i - 1 + n) % n;
      } else {
        to[i] = (i + 1) % n;
      }
    }
    for (int i = 0; i < n; i++) {
      if (good[i]) continue;
      if (to[to[i]] == i) {
        good[i] = 1;
        good[to[i]] = 1;
      }
    }
    for (int i = 0; i < n; i++) {
      deg[to[i]]++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (good[i]) continue;
      if (deg[i] == 0) {
        int node = i;
        int cnt = 0;
        while (!good[node]) {
          node = to[node];
          cnt++;
        }
        ans += com(cnt);
      }
    }
    cout << ans << "\n";
  }
}
