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