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