#include <bits/stdc++.h>
using namespace std;
int main() {
  int Q;
  cin >> Q;
  while (Q--) {
    int n, x, a, b;
    cin >> n >> x >> a >> b;
    if (a > b) {
      swap(a, b);
    }
    int posa = a - 1;
    int posb = n - b;
    if (x <= posa) {
      a -= x;
      cout << b - a << endl;
      continue;
    }
    a = 1;
    x -= posa;
    if (x < posb) {
      b += x;
      cout << b - a << endl;
      continue;
    }
    b = n;
    cout << b - a << endl;
  }
  return 0;
}
