#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long t, n, x, a, b;
  cin >> t;
  while (t--) {
    cin >> n >> x >> a >> b;
    cout << min(n - 1, abs(b - a) + x) << endl;
    ;
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
