#include <bits/stdc++.h>
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int mode = 0, cnt = 0;
    vector<int> vec;
    for (int i = 0; i < (int)(N); i++) {
      if (mode == 0 && S[i] == 'L')
        cnt++;
      else if (mode == 0 && S[i] == 'R') {
        if (cnt > 0) vec.push_back(cnt);
        mode = 1 - mode, cnt = 1;
      } else if (mode == 1 && S[i] == 'L') {
        if (cnt > 0) vec.push_back(cnt);
        mode = 1 - mode, cnt = 1;
      } else if (mode == 1 && S[i] == 'R')
        cnt++;
    }
    if (cnt > 0) vec.push_back(cnt);
    int V = vec.size();
    if (V > 1 && (V & 1)) {
      vec[0] += vec.back();
      vec.pop_back();
      V--;
    }
    int ans = 0;
    if (V == 1) {
      ans += (vec[0] + 2) / 3;
    } else {
      for (int i = 0; i < (int)(V); i++) {
        ans += vec[i] / 3;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
