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