OUTPUT CONFUSION

#include
using namespace std;

int main()
{
// your code goes here
int T,flag=0;
int n;
cin>>T;
for(int i=1;i<=T;i++)
{
cin>>n;

    for(int j=2;j<n/2;j++)
    {
       if(n%j==0)
       {
           cout<<"NO"<<endl;
           flag=1;
           break;
           
       }
    }

       if(flag==0)
       
           cout<<"YES"<<endl;
       
           
           
       
 }

return 0;

}
QUESTION LINK-:PRB01 Problem - CodeChef

MY OUTPUT
YES
YES
NO
NO

You never reset flag back to 0.

Edit:

For a more striking example, consider:

10
6
3
3
3
3
3
3
3
3
3