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