#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <utility>
#include <cmath>
#include <bitset>
using namespace std;



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    for (int t = 0; t < T; ++t) {
        string s;
        cin >> s;
        if (s.length() == 1) cout << 0 << '\n';
        else if (s.length() == 2) cout << ((s[0] == s[1]) ? 1 : 0) << '\n';
        else {
            int ans = 0;
            char x = s.front();
            for (int i = 2; i < s.length(); ++i) {
                if (s[i] != '#' && s[i - 2] == s[i - 1] && s[i - 1] == s[i - 0]) {
                    ans += 2;
                    s[i] = '#';
                    s[i - 1] = '#';
                }
                else if (s[i - 2] != '#' && s[i - 2] == s[i - 1]) {
                    ans++;
                    s[i - 1] = '#';
                }
                else if (s[i] != '#' && s[i - 1] == s[i]) {
                    ans++;
                    s[i] = '#';
                }
                else if (s[i] != '#' && s[i - 2] == s[i]) {
                    ans++;
                    s[i] = '#';
                }
            }

            cout << ans << '\n';
        }
    }
    return 0;
}