#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, n, x, a, b, r, t, d, z, m, c, f;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d%d%d", &n, &x, &a, &b);
    f = 0;
    d = abs(a - b);
    r = max(a, b);
    m = min(a, b);
    if (d + 1 == n)
      printf("%d\n", d);
    else {
      for (i = 1; i <= x; i++) {
        if (m > 1)
          m = m - 1;
        else {
          c = i - 1;
          f = 1;
          break;
        }
      }
      if (f == 1) {
        x = x - c;
        for (i = 1; i <= x; i++) {
          if (r < n) {
            r = r + 1;
          } else {
            i = x + 2;
          }
        }
      }
      r = abs(r - m);
      printf("%d\n", r);
    }
  }
  return 0;
}
