#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
 
using namespace std;
 
typedef long long ll;
 
const int Z = (int) 2e3 + 228;
const int N = (int) 1e5 + 228;
const int INF = (int) 1e9 + 228;
const ll LLINF = (ll) 1e18 + 228;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tst;
    cin >> tst;
    while (tst--) {
        string s;
        cin >> s;
        int n = s.size();
        if (n == 1) {
            cout << 0 << "\n";
            continue;
        }
        if (n == 2) {
            if (s[0] != s[1]) {
                cout << 0 << "\n";
            } else {
                cout << 1 << "\n";
            }
            continue;
        }
        set<char> mn;
        for (char c = 'a'; c <= 'z'; ++c) {
            mn.insert(c);
        }
        int ans = 0;
        for (int i = 0; i + 2 < n; ++i) {
            set<char> kek = mn;
            for (int j = i - 1; j >= max(0, i - 8); --j) {
                kek.erase(s[j]);
            }
            for (int j = i; j < min(n, i + 8); ++j) {
                kek.erase(s[j]);
            }
            if (s[i] == s[i + 1] && s[i + 1] == s[i + 2]) {
                kek.erase(s[i]);
                s[i + 1] = *kek.begin();
                s[i + 2] = *++kek.begin();
                ans += 2;
            } else if (s[i] == s[i + 1]) {
                s[i + 1] = *kek.begin();
                ++ans;
            } else if (s[i + 1] == s[i + 2]) {
                s[i + 2] = *kek.begin();
                ++ans;
            } else if (s[i] == s[i + 2]) {
                s[i + 2] = *kek.begin();
                ++ans;
            }
        }
        cout << ans << "\n";
    }
    return 0;
}
/*
1
hthtqqqqmnmnososeaeaaa
*/