TICKETS answer giving wrong answer

This code is wrong answer,in which case it is failing.

#include<iostream>
#include<cstdio>
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);


using namespace std;

int main()
{
	FAST_IO





	
int T;
cin>>T;
string s;
while(T--)
{
	cin>>s;
	
	
	
	
	if(s[0]!=s[1])
	{
		if(s.length()==2)	
			cout<<"YES"<<"\n";
		else{
		int flag=0;
		for(int i=2;i<s.length();i+=2)
		{
			if((s[0]==s[i] && s[1]==s[i+1]) || (s[0] == s[i]))
			{
				flag=1;
			}
			else
			{
				flag=0;
				break;
			}
			
		}
		if(flag == 1)
			cout<<"YES"<<"\n";
		else
			cout<<"NO"<<"\n";
	}
	
	}
	
	
	else
	{
		
		cout<<"NO"<<"\n";
	}
	



}		
		
	

    return 0;
}


It outputs YES for the testcase:

1            
ABAC