#include using namespace std; typedef long long ll; ll t,n,m,x,y; int main(){ ios::sync_with_stdio(0); cin>>t; while(t--){ cin>>n>>m>>x>>y; ll Min = min(x-1,min(m-y,n-1)); ll temp = n - 2 + abs(x - y); if(x==y){ temp++; } temp /= 2; Min = min(Min,temp); cout<