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