#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, x, a, b;
  cin >> t;
  while (t--) {
    cin >> n >> x >> a >> b;
    int l = min(a, b);
    int r = max(a, b);
    int temp = r;
    r = min(n, r + x);
    x -= abs(r - temp);
    l = max(1, l - x);
    cout << abs(r - l) << "\n";
  }
}
