#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);
    cout << (b - a) + min(x, (a - 1) + (n - b)) << endl;
  }
  return 0;
}
