#include <bits/stdc++.h>
using namespace std;
using Edge = pair<long long, long long>;
using Graph = vector<vector<int>>;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
  long long T;
  cin >> T;
  for (int t = (0); t < (T); ++t) {
    long long N, ans = 0;
    string S;
    cin >> N >> S;
    long long P[N + 1];
    for (int i = (1); i <= (N); ++i) {
      if (S[i - 1] == 'L') P[i] = i - 1;
      if (S[i - 1] == 'R') P[i] = i + 1;
      if (P[i] == 0) P[i] = N;
      if (P[i] == N + 1) P[i] = 1;
    }
    bool CAN[N + 1], CCAN[N + 1];
    for (int i = (1); i <= (N); ++i) CAN[i] = false;
    for (int i = (1); i <= (N); ++i) CCAN[i] = false;
    CAN[0] = true;
    CCAN[0] = true;
    for (int i = (1); i <= (N); ++i) {
      if (i == P[P[i]]) CCAN[i] = true;
    }
    for (int i = (1); i <= (N); ++i) {
      if (CCAN[P[i]] == true) CAN[i] = true;
    }
    long long Q[N + 1];
    for (int i = (1); i <= (N); ++i) Q[i] = 0;
    for (int i = (1); i <= (N); ++i) Q[P[i]] = i;
    for (int i = (1); i <= (N); ++i) {
      long long cnt = -2;
      if (CAN[i] == false) {
        cnt = 1;
        long long it = i;
        CAN[it] = true;
        while (CAN[P[it]] == false) {
          cnt++;
          it = P[it];
          CAN[it] = true;
        }
        it = i;
        while (CAN[Q[it]] == false) {
          cnt++;
          it = Q[it];
          CAN[it] = true;
        }
      }
      ans += (cnt + 2) / 3;
    }
    cout << ans << '\n';
  }
  return 0;
}
