#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 10;
int n, m;
int main() {
  int a, b, c, d, ans;
  int t;
  cin >> t;
  while (t--) {
    cin >> a >> b >> c >> d;
    ans = min(a - 1, abs(c - d) + b);
    cout << ans << endl;
  }
  return 0;
}
