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