#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int n, a, b, m, aa, bb, x;
  while (t--) {
    cin >> n >> x >> a >> b;
    aa = min(a, b);
    bb = max(a, b);
    m = min(x, aa - 1);
    aa -= m;
    x -= m;
    m = min(x, n - bb);
    bb += m;
    x -= m;
    cout << bb - aa << "\n";
  }
  return 0;
}
