#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5, MOD = 1e9 + 7, MAXLG = log2(MAX) + 1;
const long long inf = 1e18 + 5;
int arr[MAX];
int dp[MAX][2][2][2][2];
int vis[MAX][2][2][2][2];
int cs;
int n;
string s;
int solve(int pos, int prev, bool prev_att, int st, bool st_att) {
  if (pos == n - 1) {
    int need = 0;
    if (st_att) need = 1;
    if (prev && prev_att && need) return 1e9;
    if (!prev && !prev_att && !need) return 1e9;
    if (need) {
      if (st) {
        if (prev) return 1e9;
        return (s[pos] != 'R');
      } else
        return (s[pos] != 'R');
    } else {
      if (st)
        return (s[pos] != 'L');
      else {
        if (prev)
          return (s[pos] != 'L');
        else
          return 1e9;
      }
    }
  }
  int &ret = dp[pos][prev][prev_att][st][st_att];
  if (vis[pos][prev][prev_att][st][st_att] == cs) return ret;
  vis[pos][prev][prev_att][st][st_att] = cs;
  ret = 1e9;
  if (prev && prev_att)
    ret = min(ret, (s[pos] != 'L') + solve(pos + 1, 0, true, st, st_att));
  else if (!prev && !prev_att)
    ret = min(ret, (s[pos] != 'R') + solve(pos + 1, 1, false, st, st_att));
  else {
    ret = min(ret, (s[pos] != 'L') + solve(pos + 1, 0, prev, st, st_att));
    ret = min(ret, (s[pos] != 'R') + solve(pos + 1, 1, prev, st, st_att));
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    ++cs;
    cin >> n;
    cin >> s;
    int ans = 1e9;
    ans = min(ans, (s[0] != 'L') + solve(1, 0, 0, 0, 0));
    ans = min(ans, (s[0] != 'L') + solve(1, 0, 1, 0, 1));
    ans = min(ans, (s[0] != 'R') + solve(1, 1, 0, 1, 0));
    ans = min(ans, (s[0] != 'R') + solve(1, 1, 1, 1, 1));
    cout << ans << "\n";
  }
}
