#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, x, a, b, s = 0, o = 0;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> n >> x >> a >> b;
    s = abs(a - b);
    if (x != 0) {
      if (s < (n - 1)) {
        o = s + x;
        if (o < (n - 1)) {
          cout << o << endl;
        } else
          cout << (n - 1) << endl;
      } else
        cout << s << endl;
    } else
      cout << s << endl;
  }
}
