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