#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, x, a, b, l, r;
    cin >> n >> x >> a >> b;
    long long int tmp = min(a, b);
    if (tmp == a) {
      l = a;
      r = b;
    } else {
      l = b;
      r = a;
    }
    long long int dist = r - l, req = l - 1 + n - r;
    if (x > req)
      dist += req;
    else
      dist += x;
    cout << dist << endl;
  }
}
