https://www.codechef.com/problems/XYSTR 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 help! I am not getting where the mistake is. Please, point it out.
 
     
    