// wla a m7ma ma7ros
 
#include <algorithm>
#include <bitset>
#include <complex>
#include <cassert>
#include <deque>
#include <iostream>
#include <iomanip>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <memory>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>
 
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define INF_LL 4000000000000000000LL
#define INF 1000000000
#define EPS 1e-8
#define LL long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define setzero(a) memset(a,0,sizeof(a))
#define setdp(a) memset(a,-1,sizeof(a))
#define bits(a) __builtin_popcountll(a)
 
using namespace std;

char s[100005];
int dp[100005][2][2];
int v[100005][2][2];
int tt = 0, n;

int solve (int ind, bool last, bool pre) {
    if (ind >= n) return 0;
    int &temp = dp[ind][last][pre];
    if (v[ind][last][pre] == tt) return temp;
    v[ind][last][pre] = tt;
    temp = INF;
    if (!pre && ind > 1 && s[ind - 2] == s[ind]) {
        temp = solve(ind + 1, 1, last) + 1;
        if (!last && s[ind] == s[ind - 1])
            temp++;
    } else if (!last && ind > 0 && s[ind] == s[ind - 1]) {
        temp = solve(ind + 1, 1, last) + 1;
    } else {
        temp = min(solve(ind + 1, 1, last) + 1, solve(ind + 1, 0, last));
    }
    return temp;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        scanf("%s", s);
        n = (int) strlen(s);
        tt++;
        printf("%d\n", solve(0, 0, 0));
    }
    return 0;
}
// aa, aba
// axba
