#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int res, cnt;
void solve() {
  cin >> n >> s;
  if (s == string(n, 'L') || s == string(n, 'R')) {
    if (n <= 3)
      cout << n / 3;
    else
      cout << (n + 2) / 3;
    cout << '\n';
    return;
  }
  res = cnt = 0;
  while (s.back() == s[0]) {
    ++cnt;
    s.pop_back();
  }
  s += '$';
  for (int i = 0; i < s.size() - 1; ++i) {
    ++cnt;
    if (s[i] != s[i + 1]) {
      res += cnt / 3;
      cnt = 0;
    }
  }
  cout << res << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  if (1) {
    int t;
    cin >> t;
    while (t--) solve();
  } else {
    solve();
  }
}
