/* Author: Zhikun Wang */ #include #define debug(x) cout<<#x<<'='< void read(T &x){ x = 0;int f = 1;char ch = getchar(); while(!isdigit(ch)){if(ch == '-')f*=-1;ch = getchar();} while(isdigit(ch)){x = x*10+ch-48; ch = getchar();}x*=f; } template void read(T &x,Args&... nxt){ read(x); read(nxt...); } #define rep(i,a,b) for(int i=a;i<(b);++i) #define all(x) begin(x),end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair pii; typedef vector vi; int T; int main(){ read(T); while(T--){ ll a,b,c,d; read(a,b,c,d); ll ans = a; ans = min(ans,c-1); ans = min(ans,b-d); ans = min(ans,a-1); ans = min(ans,b-1); ans = min(ans,(a-1+abs(c-d))/2); if(c!=d){ ans = min(ans,(a-1+abs(c-d)-1)/2); } cout<