#include <bits/stdc++.h>
using namespace std;
long long ze = 0;
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.second < b.second);
}
vector<long long> vect_in(long long n) {
  vector<long long> a;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a.push_back(x);
  }
  return a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, x, a, b;
    cin >> n >> x >> a >> b;
    if (a > b) swap(a, b);
    long long ans = 0;
    if (x == 0)
      ans = b - a;
    else if (x >= (a - 1 + n - b))
      ans = n - 1;
    else {
      ans = b - a + x;
    }
    cout << ans << "\n";
  }
}
