Help me in solving CORTSENT question (1485 rating)

Hey, Can you help me? My code is not passing test case. Can you tell me why?

include
using namespace std;

int main()
{
long long int t;
cin >> t;
while (t–)
{
bool flag = 1;
string s;
int n;
cin >> n;
bool finder;
for (int j = 0; j < n && flag; j++)
{
cin >> s;
if (s[0] >= ‘a’ && s[0] <= ‘z’)
finder = 0;
else
finder = 1;
for (int i = 0; s[i] != ‘\0’; i++)
{

            if ((s[i] >= 'A' && s[i] <= 'M') || (s[i] >= 'n' && s[i] <= 'z'))
            {
                flag = 0;
                break;
            }

            if (finder)
            {
                if (s[i] >= 'a' && s[i] <= 'z')
                {
                    flag = 0;
                    break;
                }
            }
            else
            {
                if (s[i] >= 'A' && s[i] <= 'Z')
                {
                    flag = 0;
                    break;
                }
            }
            flag=1;
        }
    }

    if (flag)
        cout << "YES" << endl;
    else  
        cout << "NO" << endl;
}
return 0;

}

@yashraj0p
U have made implementation mistake.
I have implemented it in much simpler way.
Hope u will get it.

#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int32_t main()
{
       
      lli t;
       cin>>t;
       while(t--){
            lli k,k1;
            cin>>k;
            k1=k;
            lli cnt=0;
            while(k--)
            {
                string s;
                cin>>s;
                lli ch=0,ch1=0,fg=0;
                for(int i=0;i<s.size();i++)
                {
                    if(s[i]>='a'&&s[i]<='m')
                    {
                        ch=1;
                    }
                    else if(s[i]>='N'&&s[i]<='Z')
                    {
                        ch1=1;
                    }
                    else
                    {
                        fg=1;
                    }
                }
                ch=ch^ch1;
                if(ch&&!fg)
                {
                    cnt++;
                }
            }
            if(cnt==k1)
                cout<<"YES";
            else
                cout<<"NO";
            cout<<endl;

       }
}

Thanks, but can you tell me, exactly which test case my code will not surpass?