#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, a, b, x;
  cin >> t;
  for (int h = 1; h <= t; h++) {
    cin >> n >> x >> a >> b;
    int dif = abs(a - b);
    dif += x;
    cout << min(dif, n - 1) << endl;
  }
  return 0;
}
