#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t, n, x, a, b;
  cin >> t;
  while (t--) {
    int d;
    cin >> n >> x >> a >> b;
    if (a > b) {
      d = a;
      a = b;
      b = d;
    }
    if ((a - 1) > x) {
      a -= x;
      x = 0;
    } else {
      x -= (a - 1);
      a = 1;
    }
    if (n - b > x) {
      b += x;
      x = 0;
    } else {
      x -= (n - b);
      b = n;
    }
    cout << b - a << '\n';
  }
  return 0;
}
