Can someone explain me why I can't use for loop in this code?

#include<iostream>
using namespace std;

int main(){
	int t;
	cin >> t;
	while(t--){
		long long int N,A,B,A_P=0,B_P=0;
		cin >> N >>A>>B;
		string str;
		string str2 = "EQUINOX";
		bool flag=false;
		while(N--){
			cin >>str;

			for(int i=0;i<str2.length();i++){
				if(str[0] == str2[i]){
					flag = true;
					break;
				}
			}
			if(flag)
				A_P +=A;
			else
				B_P +=B;
		}

	if(A_P == B_P){
			cout<<"DRAW"<<endl;
		}
		else if(A_P > B_P)
			cout<<"SARTHAK"<<endl;
		else
			cout<<"ANURADHA"<<endl;
		}
}

Problem code: EQUINOX
Thank You!

You can use the loop there’s no issue. Just that you need to again initialize bool to false for every iteration in N loop otherwise even if it doesnt match it will remain true and update sarthak’s value as there’s no condition to make bool false again.