#include <bits/stdc++.h>
using namespace std;
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, x, a, b;
    cin >> n >> x >> a >> b;
    long long aa = max(a, b);
    long long bb = min(a, b);
    long long left = bb - 1;
    long long right = n - aa;
    if (left + right <= x)
      cout << n - 1;
    else
      cout << abs(aa - bb) + x;
    cout << "\n";
  }
  return 0;
}
