#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T>
T abs(T x) {
  if (x < 0) return -x;
  return x;
}
const double eps = 1e-8;
const double pi = acos(-1.0);
int main() {
  int tks, ks = 1, n, x, a, b;
  scanf("%d", &tks);
  while (tks--) {
    scanf("%d%d%d%d", &n, &x, &a, &b);
    if (a > b) swap(a, b);
    b = b - (a - 1);
    a = a - (a - 1);
    b = min(n, b + x);
    printf("%d\n", b - a);
  }
  return 0;
}
