#include <bits/stdc++.h>
const double pi = 4 * atan(1);
using namespace std;
const long long MOD = 1000000007;
const int MAXN = 200005;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int __tc;
  cin >> __tc;
  for (long long case_num = (1); (case_num) < (__tc + 1); ++case_num) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = count(s.begin(), s.end(), 'R');
    if (r == ((int)(s.size())) || r == 0) {
      cout << 1 + (s.size() - 1) / 3 << "\n";
      continue;
    }
    vector<int> atk(n, false);
    for (int i = 0; i < n; i++) {
      if (s[(i + 1) % n] == 'L') atk[i]++;
      if (s[(i - 1 + n) % n] == 'R') atk[i]++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (atk[i] == 0) {
        int j = i;
        int d = (s[i] == 'L' ? -1 : 1);
        int cnt = 0;
        while (s[i] == s[j]) {
          cnt++;
          j = (j + d + n) % n;
        }
        ans += cnt / 3;
      }
    }
    cout << ans << "\n";
  }
}
