#include <bits/stdc++.h>
int main() {
  int n, m, i, j, s, a, b, x, t, k, max = 0;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d %d %d", &n, &x, &a, &b);
    k = b;
    if (b > a) {
      b = a;
      a = k;
    }
    max = a - b;
    for (i = 0; i < x; i++) {
      a++;
      if (a - b > max && a - b < n) {
        max = a - b;
      }
    }
    printf("%d\n", max);
  }
}
