#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int N = 1e5+15;

char s[N];

int dp[N][2][2];

int solveDp(int ind,int p1,int p2,int n) {
  if(ind==n+1) {
    return 0;
  }
  int &ret = dp[ind][p1][p2];
  if(ret!=-1) {
    return ret;
  }
  ret = 1e9;
  bool needChange = false;
  if(ind-1>=1 && !p1) {
    if(s[ind]==s[ind-1]) {
      //must change
      needChange = true;
    }
  }
  if(ind-2>=1 && !p2) {
    if(s[ind]==s[ind-2]) {
      needChange = true;
    }
  }
  ret = min(ret, solveDp(ind+1,1,p1,n) + 1);
  if(!needChange) {
    ret = min(ret, solveDp(ind+1,0,p1,n));
  }
  return ret;
}

void solve2() {
  scanf(" %s ",s+1);
  int n = strlen(s+1);
  for(int i=0;i<=n;++i) {
    for(int j=0;j<2;++j) {
      for(int k=0;k<2;++k)
        dp[i][j][k] = -1;
    }
  }
  printf("%d\n",solveDp(1,0,0,n));
}

void solve() {
  int n;
  scanf("%d",&n);
  while(n--) {
    solve2();
  }
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}
