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