#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n, x, a, b;
    cin >> n >> x >> a >> b;
    int s1 = min(a, b), s2 = max(a, b);
    cout << min(n - s2 + s1 - 1, x) + abs(a - b) << '\n';
  }
  return 0;
}
