#include <bits/stdc++.h>
const int len = 1e9 + 7;
using namespace std;
void solve() {
  int n, x, a, b, d = 0;
  cin >> n >> x >> a >> b;
  int i = min(a, b), j = max(a, b);
  if (x == 0) {
    cout << abs(a - b) << "\n";
    return;
  }
  while (x--) {
    if (i > 1) {
      i--;
    } else if (j < n) {
      j++;
    }
    d = max(d, abs(i - j));
  }
  cout << d << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
