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