#include <bits/stdc++.h>
using namespace std;
int main() {
  int T, n, x, a, b;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d%d%d", &n, &x, &a, &b);
    if (a > b) swap(a, b);
    printf("%d\n", b - a + min(x, n - b + a - 1));
  }
  return 0;
}
