#include <bits/stdc++.h>
using namespace std;
int n;
int dis(int x, int a, int b) {
  int l, s;
  if (a > b) {
    l = a;
    s = b;
  } else {
    l = b;
    s = a;
  }
  if (n != l) {
    for (; x != 0 && l != n; x--, l++)
      ;
  }
  if (s != 1) {
    for (; x != 0 && s != 1; x--, s--)
      ;
  }
  return l - s;
}
int main() {
  int t, i;
  cin >> t;
  int x, a, b;
  for (i = 0; i < t; i++) {
    cin >> n >> x >> a >> b;
    a = dis(x, a, b);
    cout << a << endl;
  }
  return 0;
}
