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