#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, x, a, b;
    cin >> n >> x >> a >> b;
    long long ans = min(n - 1, abs(a - b) + x);
    cout << ans;
    cout << endl;
  }
}
