#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, n, a, b, x, l, m, e, d, s;
  cin >> t;
  while (t--) {
    cin >> n >> x >> a >> b;
    if (a > b) {
      l = a;
      s = b;
    } else {
      l = b;
      s = a;
    }
    d = n - l;
    if (x <= d) {
      cout << l + x - s << "\n";
      continue;
    } else
      m = x - d;
    e = s - 1;
    if (m >= e) {
      cout << n - 1 << "\n";
      continue;
    } else {
      s = s - m;
      cout << n - s << "\n";
    }
  }
  return 0;
}
