#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, x, a, b;
  cin >> n >> x >> a >> b;
  if (a > b) swap(a, b);
  int t = a;
  a = max(1, a - x);
  x -= t - a;
  t = b;
  b = min(n, b + x);
  cout << b - a << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int tt = 1;
  cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}
