#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long n, a[N], b[N], dp[N][3][4][3], yes;
string second;
long long solve(int i, int prv, int cnt, int one) {
  if (i == n) {
    if (prv == 0 && cnt == 2 && one == 1) return 1e9;
    if (prv == 1 && cnt == 2 && one == 0) return 1e9;
    if (one == 0)
      return (second[i] == 'L');
    else
      return (second[i] == 'R');
  }
  if (dp[i][prv][cnt][one] != -1) return dp[i][prv][cnt][one];
  long long ans = 1e18;
  if (i == 1) {
    ans = solve(i + 1, 0, 1, 0) + (second[i] == 'R');
    ans = min(ans, solve(i + 1, 1, 1, 1) + (second[i] == 'L'));
  } else {
    if (cnt < 2) {
      ans = solve(i + 1, 0, cnt + (prv == 0), one) + (second[i] == 'R');
      ans =
          min(ans, solve(i + 1, 1, cnt + (prv == 1), one) + (second[i] == 'L'));
    } else {
      if (prv == 0)
        ans = solve(i + 1, 1, 1, one) + (second[i] == 'L');
      else
        ans = solve(i + 1, 0, 1, one) + (second[i] == 'R');
    }
  }
  return dp[i][prv][cnt][one] = ans;
}
long long solve2(int i, int prv, int cnt, int one) {
  if (i == n) {
    if (prv == one) return 1e9;
    if (one == 0)
      return (second[i] == 'R');
    else
      return (second[i] == 'L');
  }
  if (dp[i][prv][cnt][one] != -1) return dp[i][prv][cnt][one];
  long long ans = 1e18;
  if (i == 1) {
    ans = solve2(i + 1, 0, 2, 0) + (second[i] == 'R');
    ans = min(ans, solve2(i + 1, 1, 2, 1) + (second[i] == 'L'));
  } else {
    if (cnt < 2) {
      ans = solve2(i + 1, 0, cnt + (prv == 0), one) + (second[i] == 'R');
      ans = min(ans,
                solve2(i + 1, 1, cnt + (prv == 1), one) + (second[i] == 'L'));
    } else {
      if (prv == 0)
        ans = solve2(i + 1, 1, 1, one) + (second[i] == 'L');
      else
        ans = solve2(i + 1, 0, 1, one) + (second[i] == 'R');
    }
  }
  return dp[i][prv][cnt][one] = ans;
}
void cl() {
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 4; k++) {
        for (int kk = 0; kk < 3; kk++) {
          dp[i][j][k][kk] = -1;
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> second;
    second = " " + second;
    long long tmp = 0, ans = 1e18;
    cl();
    ans = solve(1, 0, 0, 0);
    cl();
    ans = min(ans, solve2(1, 0, 0, 0));
    cout << ans << '\n';
  }
  return 0;
}
