#include <bits/stdc++.h>
using namespace std;
long long solve() {
  long long n;
  cin >> n;
  vector<pair<long long, long long> > neki;
  neki.push_back(make_pair(-1, 0));
  for (long long i = 0; i < n; i++) {
    char t;
    scanf(" %c ", &t);
    bool te = (t == 'L');
    if (neki.back().first == te)
      neki.back().second++;
    else
      neki.push_back(make_pair(te, 1));
  }
  if (neki.size() == 2)
    return (neki[1].second + 2) / 3;
  else {
    if (neki.size() % 2 == 0) {
      neki[1].second += neki.back().second;
      neki.pop_back();
    }
    long long ans = 0;
    for (auto&& v : neki) ans += v.second / 3;
    return ans;
  }
}
int main() {
  long long t;
  cin >> t;
  for (long long i = 0; i < t; i++) cout << solve() << endl;
}
