Help me in solving PR0BLEM problem

My issue

It is failing in some test cases please tell me how to modify it?

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	  int n,m;
	  cin>>n>>m;
	  bool p=0;
	  if(m==n){
	      cout<<"Yes"<<endl;
	      continue;
	  }
	  if(n>m)
	  {
	      for(int i=1; i<n; i++)
	      {    
	          if((n-i) == (m+i))
	          { p=1;
			  	break;
	        	}
	      }
	  }
	  
	  if(m>n)
	  	{
	      for(int i=1;i<m;i++)
		  {
			if((n+(3*i))==(m-i))
			{
				p=1;
				break;
			}
		 }
	 }
		if(p == 1)
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	    
	}
	
}





Problem Link: PR0BLEM Problem - CodeChef

@aazam_ali
In this question, i used the logic like this.

Let’s assume it as a number line. For any two numbers to meet at some central point, their sum should be an positive even integer, as they need to be at the same place after traversing a certain same distance.

Case1: Both n and m are odd.
Here, it is possible for them to meet as sum of any two odd number is always an even number.

Case2: One of them is even and other one is odd.
Here, it is not possible for them to ever meet at some positive integer value as, the sum of any odd and even number is an odd number.

NOTE: An exception might have been (n=0) and (m=1), but we have been provided the constraints that (1≤N,M≤100).

Case3: Both n and m are even.
Here, it is possible for them to meet as sum of two even numbers is always an even number.

# cook your dish here
for _ in range(int(input())):
    n,m=map(int,input().split())
    if((n+m)%2==0):
        print('yes')
    else:
        print('no')

Following code is in Python but the same logic will be applicable.

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		        Scanner scanner = new Scanner(System.in);

        int T = scanner.nextInt();

       
        for (int i = 0; i < T; i++) {
            
            int N = scanner.nextInt();
            int M = scanner.nextInt();

           
            if (Math.abs(N - M) % 2 == 0) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }

	}
}

```[quote="daneshnaik, post:3, topic:107778, full:true"]

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner scanner = new Scanner(System.in);

    int T = scanner.nextInt();

   
    for (int i = 0; i < T; i++) {
        
        int N = scanner.nextInt();
        int M = scanner.nextInt();

       
        if (Math.abs(N - M) % 2 == 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

}

}

[/quote]

this is what i did in java you can use logic