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