#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    string s;
    cin >> s;
    int r = 0, l = 0;
    for (int i = 0; i < n; i++) {
      if (s.at(i) == 'R')
        r++;
      else
        l++;
    }
    if (r == 0 || l == 0) {
      printf("%d\n", ((n + 2) / 3));
      continue;
    }
    int c = 1, c1 = 0;
    for (int i = 1; i < n; i++) {
      if (s.at(i) != s.at(i - 1)) break;
      c++;
    }
    for (int i = n - 2; i >= 0; i--) {
      if (s.at(i) != s.at(i + 1)) break;
      c1++;
    }
    int cnt = 1;
    long long int ans = 0LL;
    int flag = 0, cnt1 = 0;
    for (int i = 1; i < n; i++) {
      if (s.at(i) == s.at(i - 1)) cnt++;
      if (s.at(i) != s.at(i - 1) || i == (n - 1)) {
        if (flag == 0) {
          cnt1 = cnt;
          flag = 1;
        }
        ans = ans + 1LL * (cnt / 3LL);
        cnt = 1;
      }
    }
    if (s.at(0) == s.at(n - 1))
      ans = ans - (1LL * (cnt1 / 3) + 1LL * ((c1 + 1) / 3)) +
            1LL * ((c1 + cnt1 + 1) / 3);
    printf("%lld\n", ans);
  }
  return 0;
}
