#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int tt;
  cin >> tt;
  while (tt--) {
    int n, x, a, b;
    cin >> n >> x >> a >> b;
    int cur = (x - abs(min(a, b) - 1) - abs(n - max(a, b)));
    if (cur < 0)
      cout << abs(a - b) + x << endl;
    else
      cout << abs(a - b) + abs(min(a, b) - 1) + abs(n - max(a, b)) << endl;
  }
  return 0;
}
