#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n, x, a, b, result;
    cin >> n >> x >> a >> b;
    if (a > b) {
      result = a - b + x;
      if (result >= n) {
        result = n - 1;
      }
    } else if (a < b) {
      result = b - a + x;
      if (result >= n) result = n - 1;
    }
    cout << result << "\n";
  }
  return 0;
}
