#include <bits/stdc++.h>
int main() {
  int t, n, x, a, b, d;
  scanf("%d", &t);
  for (int i = 1; i <= t; i++) {
    scanf("%d %d %d %d", &n, &x, &a, &b);
    d = abs(a - b);
    d = d + x;
    if (d > n - 1)
      printf("%d\n", n - 1);
    else
      printf("%d\n", d);
  }
  return 0;
}
