#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int n, x, a, b;
    cin >> n >> x >> a >> b;
    int tmp = min(a, b);
    b = max(a, b);
    a = tmp;
    int ans = b - a;
    int need = (n - b) + (a - 1);
    cout << ans + min(need, x) << endl;
  }
}
