#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 5e5 + 20;
const long long mod = 1e9 + 7;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x, a, b;
    cin >> n >> x >> a >> b;
    cout << min(abs(b - a) + x, n - 1) << endl;
  }
}
