Help me in solving MNXR problem

My issue

how to optimise my code from O(n*m) to calculate xor of distances

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	for(int i=0;i<t;i++){
	    int n,m;
	    cin>>n>>m;
	    int x,y;
	    cin>>x>>y;
	    int ans=0;
	    for(int i=1;i<=n;i++){
	        for(int j=1;j<=m;j++){
	            int distance = (abs(i-x)+abs(j-y));
	            ans = ans^distance;
	        }
	    }
	    cout<<ans<<endl;   
	}

}

Problem Link: Manhattan Xor Practice Coding Problem - CodeChef