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