#include <bits/stdc++.h>   using namespace std;   char str[200005];   int main() {     int ts;     scanf( %d , &ts);     while (ts--) {       int n;       scanf( %d %s , &n, str);       vector<int> vec;       for (int i = 0; i < n; i++) {         int j = i, c = 0;         while (i < n && str[i] == str[j]) i++, c++;         i--;         vec.push_back(c);       }       if (vec.size() == 1 && vec[0] > 2) vec[0] += 2;       if (vec.size() != 1 && str[0] == str[n - 1])         vec[0] += vec.back(), vec.pop_back();       int res = 0;       for (int i = 0; i < vec.size(); i++) res += vec[i] / 3;       printf( %d n , res);     }     return 0;   }   