
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int M = 1000000000;

bool isGood(string& s, int i, int c)
{
    if (i > 0) if (s[i - 1] - 'a' == c) return false;
    if (i > 1) if (s[i - 2] - 'a' == c) return false;
    if (i < s.size() - 1) if (s[i + 1] - 'a' == c) return false;
    if (i < s.size() - 2) if (s[i + 2] - 'a' == c) return false;
    return true;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;
    for (int t1 = 0; t1 < t; t1++)
    {
        string s;
        cin >> s;
        string org = s;
        int n = s.size();

        if (n == 1) cout << 0 << "\n";
        else
        {
            vector<vector<vector<int>>> dp(n, vector<vector<int>>(2, vector<int>(2, M)));

            if (s[0] == s[1]) {
                dp[1][0][0] = M;
            } else dp[1][0][0] = 0;
            dp[1][1][0] = 1;
            dp[1][0][1] = 1;
            dp[1][1][1] = 2;

            for (int i = 2; i < n; i++)
            {

                for (int j = 0; j <= 1; j++)
                {
                    for (int k = 0; k <= 1; k++)
                    {
                        for (int l = 0; l <= 1; l++)
                        {
                            if (k == 0 && l == 0)
                            {
                                if (s[i] == s[i - 1])
                                {
                                    continue;
                                }
                            }
                            if (j == 0 && l == 0)
                            {
                                if (s[i] == s[i - 2])
                                {
                                    continue;
                                }
                            }
                            dp[i][k][l] = min(dp[i][k][l], dp[i - 1][j][k] + l);
                            //cout << i << " " << k << " " << l << " e " << " " << j << k << endl;
                            //cout << dp[i][k][l] << endl;
                        }
                    }
                }
            }

            int best = M;
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    best = min(best, dp[n - 1][i][j]);
                }
            }
            cout << best << "\n";
        }
    }
}
