#include <bits/stdc++.h>
using namespace std;
int arr[200050];
int N;
int id = 1;
int vis[2][2][2][200050];
int memo[2][2][2][200050];
int dp(int first, int second, int last, int cur) {
  if (cur == N) {
    if (first == second && last == first) return 1e8;
    return 0;
  }
  if (cur == N - 1) {
    if (arr[cur] == last && arr[cur] == first) return 1;
    if (second == first && first == arr[cur]) return 1;
    return 0;
  }
  if (vis[first][second][last][cur] == id)
    return memo[first][second][last][cur];
  vis[first][second][last][cur] = id;
  int& d = memo[first][second][last][cur];
  d = 1e8;
  if (last == 0) {
    d = min(d, dp(first, second, 1, cur + 2) + (arr[cur] != 0 ? 1 : 0) +
                   (arr[cur + 1] != 1 ? 1 : 0));
    d = min(d, dp(first, second, 1, cur + 1) + (arr[cur] != 1 ? 1 : 0));
  } else {
    d = min(d, dp(first, second, 0, cur + 2) + (arr[cur] != 1 ? 1 : 0) +
                   (arr[cur + 1] != 0 ? 1 : 0));
    d = min(d, dp(first, second, 0, cur + 1) + (arr[cur] != 0 ? 1 : 0));
  }
  return d;
}
int mind(int a, int b) {
  cout << "min: " << a << " " << b << endl;
  return min(a, b);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T, K;
  cin >> T;
  while (T--) {
    cin >> N;
    char c;
    for (int i = 0; i < N; i++) {
      cin >> c;
      if (c == 'R')
        arr[i] = 0;
      else
        arr[i] = 1;
    }
    if (N < 3) {
      cout << 0 << "\n";
      continue;
    }
    if (N == 3) {
      if (arr[0] == arr[1] && arr[1] == arr[2])
        cout << 1 << "\n";
      else
        cout << 0 << "\n";
      continue;
    }
    id++;
    int ans = 1e8;
    int a = 0, b = 0;
    ans = min(ans, dp(0, 0, 1, 3) + (arr[0] != a ? 1 : 0) +
                       (arr[1] != b ? 1 : 0) + (arr[2] != 1 ? 1 : 0));
    a = 0;
    b = 1;
    ans = min(ans,
              dp(0, 1, 1, 2) + (arr[0] != a ? 1 : 0) + (arr[1] != b ? 1 : 0));
    a = 1;
    b = 0;
    ans = min(ans,
              dp(1, 0, 0, 2) + (arr[0] != a ? 1 : 0) + (arr[1] != b ? 1 : 0));
    a = 1;
    b = 1;
    ans = min(ans, dp(1, 1, 0, 3) + (arr[0] != a ? 1 : 0) +
                       (arr[1] != b ? 1 : 0) + (arr[2] != 0 ? 1 : 0));
    cout << ans << "\n";
  }
  return 0;
}
