#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, x, a, b;
    cin >> n >> x >> a >> b;
    if (x == 0 || max(a, b) == n && min(a, b) == 1)
      cout << abs(a - b) << "\n";
    else {
      long long int ans = abs(a - b);
      long long int up = abs(max(a, b) - n);
      long long int dn = min(a, b) - 1;
      long long int z = up + dn;
      if (z < x)
        cout << ans + z << "\n";
      else
        cout << ans + x << "\n";
    }
  }
}
