Help me in solving XYSTRP problem

My issue

a=int(input())
for b in range(a):
c=str(input())#‘xyxxy’
d=list(c)#[x,x,y,y]
e=0
for i in range(len(d)-1):
if d[i]==‘x’ and d[i+1]==‘y’ or d[i]==‘y’ and d[i+1]==‘x’:
e=e+1
for j in range(len(d)-2):
if d[j]==‘x’ and d[j+1]==‘y’ and d[j+2]==‘x’:
e=e-1
if e>0:
print(e)
else:
print(0)

#please find error, on submission its showing wrong answer

My code

a=int(input())
for b in range(a):
    c=str(input())
    d=list(c)
    e=0
    for i in range(len(d)-1):
        if d[i]=='x' and d[i+1]=='y' or d[i]=='y' and d[i+1]=='x':
            e=e+1
    for j in range(len(d)-2):        
        if d[j]=='x' and d[j+1]=='y' and d[j+2]=='x':
            e=e-1
    if e>0:
        print(e)
    else:
        print(0)
    
    

Learning course: Greedy Algorithms
Problem Link: Chef and String Practice Problem in Greedy Algorithms - CodeChef

@arush12
here plzz refer my c++ code for better understanding of the logic and implementation

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    string s;
	    cin>>s;
	    int ans=0;
	    for(int i=1;i<s.size();i++)
	    {
	        if(s[i]!=s[i-1])
	        {
	            ans++;
	            i++;
	        }
	    }
	    cout<<ans<<endl;
	}

}