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