#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n;
    string s;
    cin >> n >> s;
    int c = 0, ans = 0;
    char x = s[0];

    for (char z : s) {
        if (x == z) c++;
        else {
            ans += c/3;
            x = z; c = 1;
        }
    }
    cout << ans+c/3 << '\n';
}

int main() {
    int t;
    cin >> t;
    while (t--) solve();
}
