#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int n, x, p, s;
  for (int i = 0; i < t; i++) {
    cin >> n >> x >> p >> s;
    int x1, x2;
    x1 = min(p, s);
    x2 = max(p, s);
    for (int j = 0; j < x; j++) {
      if (x2 < n) {
        x2++;
      } else if (x1 > 1) {
        x1--;
      }
    }
    cout << x2 - x1 << endl;
  }
}
