#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, x, a, b;
  cin >> t;
  while (t--) {
    cin >> n >> x >> a >> b;
    if (a < b) {
      int tmp = a;
      a = b;
      b = tmp;
    }
    if (a + x <= n)
      a += x;
    else {
      x -= abs(a - n);
      a = n;
      if (b - x >= 1) {
        b -= x;
      } else {
        b = 1;
      }
    }
    cout << (a - b) << endl;
  }
  return 0;
}
