Please helpppp i am not getting my mistake please point it out

my code is
#include <bits/stdc++.h>

using namespace std;

int main()

{

int t;

cin >> t;

while (t--)

{

    string str;

    int flag = 0, num = 0;

    cin >> str;

    for (int i = 0; str[i] != '\0'; i++)//xy xy xy xx xy yx

    {                                   //1  1  1     1  1 

        if(str[i]== 'x' && str[i+1] == 'y') 

       {

           num++;

           i++;

       }

       if(  str[i] == 'y' && str[i+1] == 'x')

       {

           num++;

           i++;

       }

       }

        cout << num<< endl;

    }

   

}

please helpppp i am not getting my mistake please point it out