#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 (size_t tc = 1; tc <= t; tc++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a - 1, (abs(c - d) + b)) << "\n";
  }
  return 0;
}
