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