#include <bits/stdc++.h>
using namespace std;
long long int n, a, b, c, d, e, f;
int main() {
  cin >> n;
  while (n--) {
    cin >> a >> b >> c >> d;
    f = abs(c - d) + b;
    e = min(a - 1, f);
    cout << e << endl;
  }
}
