#include <bits/stdc++.h>
char _;
using namespace std;
void PRINT(int x, int y) {
  for (int i = y - 1; i >= 0; i--) {
    cout << ((0u == (x & (1 << i))) ? 0u : 1u);
  }
  cout << endl;
}
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
int n;
string s;
int dp[2][4][200010];
int solve(bool l, int csc, int pos) {
  bool L = (s[pos] == 'L');
  if (dp[l][csc][pos] != -1) {
    return dp[l][csc][pos];
  } else if (pos == n - 1) {
    if ((l && s[pos] == 'L') || (!l && s[pos] == 'R')) {
      if (csc == 2) {
        if (s[0] != s[pos] && s[1] != s[pos]) {
          dp[l][csc][pos] = 10000000;
        } else {
          dp[l][csc][pos] = 1;
        }
      } else {
        if (s[pos] == s[0]) {
          dp[l][csc][pos] = 1;
        } else {
          dp[l][csc][pos] = 0;
        }
      }
    } else {
      if (s[0] == s[pos] && s[1] == s[pos]) {
        if (csc == 2) {
          dp[l][csc][pos] = 10000000;
        } else {
          dp[l][csc][pos] = 1;
        }
      } else {
        dp[l][csc][pos] = 0;
      }
    }
  } else {
    dp[l][csc][pos] = 10000000;
    if (l && s[pos] == 'L') {
      if (csc == 2) {
        dp[l][csc][pos] = solve(false, 1, pos + 1) + 1;
      } else {
        dp[l][csc][pos] = min({dp[l][csc][pos], solve(false, 1, pos + 1) + 1,
                               solve(true, csc + 1, pos + 1)});
      }
    } else if (!l && s[pos] == 'R') {
      if (csc == 2) {
        dp[l][csc][pos] = solve(true, 1, pos + 1) + 1;
      } else {
        dp[l][csc][pos] = min({dp[l][csc][pos], solve(true, 1, pos + 1) + 1,
                               solve(false, csc + 1, pos + 1)});
      }
    } else {
      dp[l][csc][pos] = solve(!l, 1, pos + 1);
      if (csc < 2) {
        dp[l][csc][pos] = min(dp[l][csc][pos], solve(l, csc + 1, pos + 1) + 1);
      }
    }
  }
  return dp[l][csc][pos];
}
void reset() {
  for (int x = 0; x < n + 5; x++) {
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 4; j++) {
        dp[i][j][x] = -1;
      }
    }
  }
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> s;
    string cur = s;
    int ans = numeric_limits<int>::max();
    if (n < 3) {
      cout << 0 << "\n";
    } else {
      char v[2] = {'L', 'R'};
      for (int x = 0; x < 2; x++) {
        for (int i = 0; i < 2; i++) {
          int tmp = (cur[0] != v[x]) + (cur[1] != v[i]);
          s[0] = v[x];
          s[1] = v[i];
          reset();
          if (s[1] == 'L') {
            if (s[0] == s[1]) {
              ans = min(ans, solve(true, 2, 2) + tmp);
            } else {
              ans = min(ans, solve(true, 1, 2) + tmp);
            }
          } else {
            if (s[0] == s[1]) {
              ans = min(ans, solve(false, 2, 2) + tmp);
            } else {
              ans = min(ans, solve(false, 1, 2) + tmp);
            }
          }
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
