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