#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, i;       cin >> n;       string s;       int ans = 0;       cin >> s;       for (i = 1; i < n; i++) {         if (s[i] != s[0]) break;       }       if (i != n) {         int c = 1;         for (int j = i + 1; j != i; j = (j + 1) % n) {           if ((j != 0 && s[j] == s[j - 1]) || (j == 0 && s[0] == s[n - 1])) {             c++;           } else {             while (c >= 3) {               ans++;               c -= 3;             }             c = 1;           }         }         while (c >= 3) {           ans++;           c -= 3;         }       } else {         int c = n - 1;         ans = 1;         while (c >= 3) {           ans++;           c -= 3;         }       }       cout << ans << endl;     }   }   