#include <bits/stdc++.h>
using namespace std;
//4/
using namespace std::chrono; 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define _USE_MATH_DEFINES
#define cin_exp cin.exceptions(cin.failbit);
#define dis_inbf cin.ignore(numeric_limits<streamsize>::max(),'\n'); //discards the imput buffer
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define repG(i, n)    for(ll i = 0; i < (n); ++i)
#define rep(i, a, n)  for(ll i = a; i < (n); ++i)
#define repd(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fill_2(a,b)  memset(a, 0, sizeof (a));memset(b, 0, sizeof (b));
#define fill_n(a) memset(a,-1,sizeof(a))
#define fst first
#define snd second
#define mpr make_pair
#define pb push_back
#define eb emplace_back
#define mod 998244353//1000000007//000000000000007//1000000009
#define PI  3.14159265358979323846264
#define fftmod 998244353
#define arr_106 1000011
#define arr_105 100011
#define ll_inf 1223372036854775807
#define int_inf 1147483647
#define endl "\n"
#define sort_vec(v) sort(v.begin(),v.end())
#define sort_vecr(v) sort(v.rbegin(),v.rend())
#define all_of(v) v.begin(),v.end()
#define l_b lower_bound
#define u_b upper_bound
#define trace_1(a) for(auto i:a) cout<<i<<" ";cout<<endl;
#define trace_2(a,b) for(auto i:a)cout<<i<<" ";cout<<endl;for(auto i:b)cout<<i<<" ";cout<<endl;
#define setpres() cout << fixed << setprecision(16);
#define n_l cout<<endl;
#define in_1(n) cin>>n;
#define input(a) for(auto &it:a) cin>>it;
//#define int long long

//////////////////// DEBUG /////////////////////////////////////////
#ifdef LOCAL
#define D(x) cerr << #x << " is:\t" << x << '\n';
#define DD(x, y) cerr << '(' << #x << ',' << #y << ") are:\t" << x << ' ' << y << '\n';
#define DDD(x, y, z) cerr << '(' << #x << ',' << #y << ',' << #z << ") are:\t" << x << ' ' << y << ' ' << z << '\n';
#else
#define D(x) ;
#define DD(x, y) ;
#define DDD(x, y, z) ;
#endif

 
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ll, pii> pip;
typedef pair<pii, ll> ppi;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef map<ll,ll> mii;
typedef map<pii,ll> mpi;

ll fac[1000006];
 
 
inline ll exp(ll x,ll n){ll r=1;x=x;while(n){if(n%2)r=(r*x)%mod;x=(x*x)%mod;n=n/2;}return r;}
inline ll mmi(ll a){return exp(a,mod-2)%mod;}
inline ll fact(ll n){ll res=1;rep(i,1,n+1){res=(res*i)%mod;}return res;}
inline void fact_a(){fac[0]=1;fac[1]=1;rep(i,1,1000005){fac[i]=(fac[i-1]*i)%mod;}}
inline ll inv_fact(ll n){/*fact_a();*/ll par=fac[n];ll res=mmi(par);return res;}
inline ll comb(ll n,ll r){/*fact_a();*/if(n==r && r==0)return 1;if(n<r)return 0;return ((fac[n]*inv_fact(r))%mod*inv_fact(n-r))%mod;}
 
struct triplet{ll a,b,c;};
bool operator < (const triplet &t1,const triplet &t2){
    if(t1.a<t2.a)return true;
    if(t1.a==t2.a && t1.b <t2.b)return true;
    if(t1.a==t2.a && t1.b ==t2.b && t1.c<t2.c)
        return true;return false;}
 
pair<ll,pii > ex_gcd(ll a,ll b)
{   if(b==0){return mpr(a,mpr(1,0));}
    pip p=ex_gcd(b,a%b);
    ll gcd=p.fst;ll x1=p.snd.fst;ll y1=p.snd.snd;
    ll x=y1;ll y=x1-(a/b)*y1;
    return mpr(gcd,mpr(x,y));
} 
ll prime[3000006];
ll spf_prime[3000006];
void sieve(){prime[1]=1;for(ll i=2;i*i<=3000000;i++)if(prime[i]==0)for(ll j=i*i;j<=3000000;j+=i)prime[j]=1;}
void spf(){
     for(ll i=2;i*i<=3000000;i++)if(!spf_prime[i])for(ll j=i*i;j<=3000000;j+=i)if(!spf_prime[j])spf_prime[j]=i;
        for(ll i=2;i<=3000000;i++)if(!spf_prime[i])spf_prime[i]=i;
}
 
ll getparent_BIT(ll idx)
{
    return idx-(idx& -idx);
}
ll getnext_BIT(ll idx)
{
    return idx+(idx& -idx);
}
ll getsum_BIT(ll idx,ll BIT[],ll n)
{   
    idx++;
    ll sum=0;
    while(idx>0)
    {
      sum=max(sum,BIT[idx]);
      idx=getparent_BIT(idx);
      
    }
    return sum;
}
void update_BIT(ll idx,ll BIT[],ll val,ll n)
{
    idx++;
    while(idx<=n)
    {
        BIT[idx]=max(BIT[idx],val);
        idx=getnext_BIT(idx);
    }
}

void build_BIT(ll BIT[],ll a[],ll n)
{
    rep(i,0,n)
    {
        update_BIT(i,BIT,a[i],n);
    }
}
 
void comp_lps(string s,ll lps[],ll n)
{  ll i=1,j=0;
    while(i<n){if(s[i]==s[j]){lps[i++]=++j;}
        else{ if(j!=0) j=lps[j-1]; else lps[i++]=0;}}
}
 
 
void dfs_l(ll u,vvi &adj,ll status[])
{
    if(status[u]==1) return;status[u]=1;
    rep(i,0,adj[u].size())
      dfs_l(adj[u][i],adj,status);
}
ll dij(ll u,ll n,vector<vector<pii> > &adj,ll status[])
{
    ll dist[n];
    rep(i,0,n) dist[i]=1000000000;
    dist[0]=0;
    priority_queue<pii,vpi,greater<pii> > q;
    q.push(mpr(0,0));
    while(!q.empty())
    {
        pii p;
        p=q.top();
        q.pop();
        ll x=p.snd;
        ll w=p.fst;
        if(status[x]==1) continue;
        status[x]=1;
        rep(i,0,adj[x].size())
        {
            ll ww=adj[x][i].fst;
            ll y=adj[x][i].snd;
            if(dist[x]+ww<dist[y])
            {
                dist[y]=dist[x]+ww;
                q.push(mpr(dist[y],y));
            }
        }
    }
    if(dist[n-1]>=1000000000) return -1;
    return dist[n-1];
}
ll phi(ll n)
{
    vi v;
    ll k=n;;
    for(ll i=2;i*i<=n;i++)
    {
        if(k%i==0)
        {
            v.pb(i);
            while(k%i==0) k/=i;
        }
    }
    if(k>1) v.pb(k);
    ll ans=n;
    rep(i,0,v.size())
      ans-=(ans/v[i]);
    return ans;
}
struct trie
{
   struct trie *left,*right;
   bool isend;
};
trie* get_trie()
{
    trie* ptr=new trie;
    ptr->left=NULL;
    ptr->right=NULL;
    ptr->isend=false;
    return ptr;
}
bool isempty(trie* root)
{
    if(root->left==NULL && root->right==NULL) return true;
    return false;
}
void insert_trie(trie *root,string key)
{   
    trie *ptr=root;
    rep(i,0,key.size())
    {
        if(key[i]=='0')
        {
            if(ptr->left==NULL)
            {
                ptr->left=get_trie();
            }
            ptr=ptr->left;
        }
        else
        {
            if(ptr->right==NULL)
                 ptr->right=get_trie();
            ptr=ptr->right;
        }
    }
    ptr->isend=true;
}
trie* remove_trie(trie *root,string key,ll idx=0)
{
    if(root==NULL) return NULL;
    if(idx==key.size())
    {
        if(isempty(root))
        {  
            delete(root);
            root=NULL;
        }
        return root;
    }
    if(key[idx]=='0')
        root->left=remove_trie(root->left,key,idx+1);
    else
        root->right=remove_trie(root->right,key,idx+1);
    if(isempty(root))
    { 
        delete(root);
        root=NULL;
    }
    return root;
}
ll search_trie(trie *root,string key)
{
    trie *ptr=root;
    string s="";
    rep(i,0,key.size())
    {
        if(key[i]=='0')
        {
            if(ptr->right!=NULL)
            {  
                ptr=ptr->right;s+='1';
            }
            else
            {
                ptr=ptr->left;s+='0';
            }
        }
        else
        {
            if(ptr->left!=NULL)
            {
                ptr=ptr->left;s+='1';
            }
            else
            {
                ptr=ptr->right;s+='0';
            }
        }
    }
    ll res=0;
    reverse(s.begin(),s.end());
    
    repd(i,s.length()-1,0)
      res=res*2+(s[i]-'0');
    return res;
}
// ifstream fin("input.txt");ofstream fout("output.txt");
/*
#ifndef ONLINE_JUDGE
    double _tBeg=clock();
#endif
*/
/*double cal(ll h,ll c,ll mid)
{
    double f=(double)(h*(mid+1)+ c*(mid))/(double)(2*mid+1);
    return f;
}*/

struct Comp {
  bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b) {
    if (a.first != b.first) {
      return a.first < b.first;
    }
    return a.second > b.second;
  }
   /*Comp comp_functor;
    std::sort(v.begin(), v.end(), comp_functor);*/

};


void dearr()
{
   ll dar[1005];
   dar[0]=1;dar[1]=0;dar[2]=1;
   rep(i,3,1002)
   {
      dar[i]=(i-1)*(dar[i-1]+dar[i-2]);
   }
}
struct dsu
{
ll siz[200002];
ll parent[200002];
void make_set(ll v)
{
    parent[v]=v;
    siz[v]=1;
}
ll find_set(ll v)
{
    if(v==parent[v]) return v;
    return parent[v]=find_set(parent[v]);
}
void union_set(ll a,ll b)
{
    a=find_set(a);
    b=find_set(b);
    if(a!=b)
    {
        if(siz[a]<siz[b]) swap(a,b);
        parent[b]=a;
        siz[a]+=siz[b];
    }
}

};

ll dist[200006];
void dij(ll s,vector<vpi> &adj,ll n)
{
    priority_queue<pii,vpi,greater<pii> > q;
    q.push(mpr(0,s));
    ll status[n+2];
    fill(status);
    while(!q.empty())
    {
        pii p=q.top();
        q.pop();
        if(status[p.snd]==1) continue;
        status[p.snd]=1;
        ll u=p.snd;
        ll w=p.fst;
        rep(i,0,adj[u].size())
        {   ll v=adj[u][i].snd;
            ll ww=adj[u][i].fst;
            if(dist[u]+ww < dist[v])
            {
                dist[v]=dist[u]+ww;
                q.push(mpr(dist[v],v));
            }
        }
    }
}
ll rec(ll u,vvi &adj,ll status[],ll d[],ll p[])
{
    if(status[u]==1) return 0;
    status[u]=1;
    ll a=0;
    rep(i,0,adj[u].size())
    {
      a+=rec(adj[u][i],adj,status,d,p);
    } 

    return d[u]=a+p[u];
}
ll rec1(ll u,vvi &adj,ll status[],ll d[],ll h[],ll &dd,ll p[])
{
    status[u]=1;
    ll b=0;
    ll cc=0;
    for(auto it:adj[u])
    {   if(status[it]==1) continue;
        b+=rec1(it,adj,status,d,h,dd,p);
        cc=1;
    }
    if(!cc)
    {
        if((h[u]+d[u]+2)%2==1 || h[u]<(-d[u]) || h[u]>(d[u]))
        {dd=1; return 0;}
        else return (d[u]-h[u])/2;
    }

    ll H=d[u]-2*(b+p[u]);
      if((h[u]+d[u]+2)%2==1 || h[u] < H || h[u]>d[u])
        {dd=1;return 0;}
    return (d[u]-h[u])/2;

}
int main()
{
    #ifndef ONLINE_JUDGE
    double _tBeg=clock();
    #endif
     
    IOS;
    ll t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        ll n=s.length();
        ll cnt=0;

        rep(i,1,n)
        {   

            if(i==1)
            {
                if(s[i]!=s[i-1]) continue;
                char c;
                if('a'!=s[i-1] && (i+1>=n || 'a'!=s[i+1]) && (i+2>=n || 'a'!=s[i+2]))
                {
                    c='a';
                }
                else if('b'!=s[i-1] && (i+1>=n || 'b'!=s[i+1]) && (i+2>=n || 'b'!=s[i+2]))
                {
                    c='b';
                }
                else if('c'!=s[i-1] && (i+1>=n || 'c'!=s[i+1]) && (i+2>=n || 'c'!=s[i+2]))
                {
                    c='c';
                }
                else if('d'!=s[i-1] && (i+1>=n || 'd'!=s[i+1]) && (i+2>=n || 'd'!=s[i+2]))
                {
                    c='d';
                }
                s[i]=c;
                cnt+=1;
            }
            else
            {
              if(s[i]!=s[i-1] && s[i]!=s[i-2]) continue;
                char c='e';
                if('a'!=s[i-2] && 'a'!=s[i-1] && (i+1>=n || 'a'!=s[i+1]) && (i+2>=n || 'a'!=s[i+2]))
                {
                    c='a';
                }
                else if('b'!=s[i-2] && 'b'!=s[i-1] && (i+1>=n || 'b'!=s[i+1]) && (i+2>=n || 'b'!=s[i+2]))
                {
                    c='b';
                }
                else if('c'!=s[i-2] &&  'c'!=s[i-1] && (i+1>=n || 'c'!=s[i+1]) && (i+2>=n || 'c'!=s[i+2]))
                {
                    c='c';
                }
                else if('d'!=s[i-2] &&  'd'!=s[i-1] && (i+1>=n || 'd'!=s[i+1]) && (i+2>=n || 'd'!=s[i+2]))
                {
                    c='d';
                }
                s[i]=c;   
                cnt+=1;
            }
        }
        cout<<cnt<<endl;
    }

    
    
   #ifndef ONLINE_JUDGE
    double _tEnd=clock();
    printf("total time %.6f\n",(_tEnd-_tBeg)/CLOCKS_PER_SEC);
    #endif
    
    
    
}




