#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long dp[4][(long long)1e6];
long long a[(long long)1e6];
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    for (long long i = 0; i < n; i++) a[i] = (s[i] == 'L' ? 0 : 1);
    long long ans = 2 * n;
    dp[0][1] = (a[0] != 0) + (a[1] != 0);
    dp[1][1] = 2 * n;
    dp[2][1] = 2 * n;
    dp[3][1] = 2 * n;
    for (long long i = 2; i < n; i++) {
      dp[0][i] = dp[2][i - 1] + (a[i] != 0);
      dp[1][i] = min(dp[0][i - 1], dp[2][i - 1]) + (a[i] != 1);
      dp[2][i] = min(dp[1][i - 1], dp[3][i - 1]) + (a[i] != 0);
      dp[3][i] = dp[1][i - 1] + (a[i] != 1);
    }
    ans = min(ans, dp[1][n - 1]);
    ans = min(ans, dp[3][n - 1]);
    dp[0][1] = 2 * n;
    dp[1][1] = (a[0] != 0) + (a[1] != 1);
    dp[2][1] = 2 * n;
    dp[3][1] = 2 * n;
    for (long long i = 2; i < n; i++) {
      dp[0][i] = dp[2][i - 1] + (a[i] != 0);
      dp[1][i] = min(dp[0][i - 1], dp[2][i - 1]) + (a[i] != 1);
      dp[2][i] = min(dp[1][i - 1], dp[3][i - 1]) + (a[i] != 0);
      dp[3][i] = dp[1][i - 1] + (a[i] != 1);
    }
    ans = min(ans, dp[1][n - 1]);
    ans = min(ans, dp[2][n - 1]);
    ans = min(ans, dp[3][n - 1]);
    dp[0][1] = 2 * n;
    dp[1][1] = 2 * n;
    dp[2][1] = (a[0] != 1) + (a[1] != 0);
    dp[3][1] = 2 * n;
    for (long long i = 2; i < n; i++) {
      dp[0][i] = dp[2][i - 1] + (a[i] != 0);
      dp[1][i] = min(dp[0][i - 1], dp[2][i - 1]) + (a[i] != 1);
      dp[2][i] = min(dp[1][i - 1], dp[3][i - 1]) + (a[i] != 0);
      dp[3][i] = dp[1][i - 1] + (a[i] != 1);
    }
    ans = min(ans, dp[0][n - 1]);
    ans = min(ans, dp[1][n - 1]);
    ans = min(ans, dp[2][n - 1]);
    dp[0][1] = 2 * n;
    dp[1][1] = 2 * n;
    dp[2][1] = 2 * n;
    dp[3][1] = (a[0] != 1) + (a[1] != 1);
    for (long long i = 2; i < n; i++) {
      dp[0][i] = dp[2][i - 1] + (a[i] != 0);
      dp[1][i] = min(dp[0][i - 1], dp[2][i - 1]) + (a[i] != 1);
      dp[2][i] = min(dp[1][i - 1], dp[3][i - 1]) + (a[i] != 0);
      dp[3][i] = dp[1][i - 1] + (a[i] != 1);
    }
    ans = min(ans, dp[0][n - 1]);
    ans = min(ans, dp[2][n - 1]);
    cout << ans << endl;
  }
}
