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