#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  long long T, t;
  cin >> T;
  for (t = (0); t < (T); ++t) {
    long long n, x, a, b;
    cin >> n >> x >> a >> b;
    if (a < b) swap(a, b);
    cout << min((a - b + x), n - 1) << endl;
  }
  return 0;
}
