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