#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;
    if (a > b) swap(a, b);
    while (a != 1) {
      if (x > 0) {
        a--;
        x--;
        if (a == 1) break;
      } else
        break;
    }
    while (b != n) {
      if (x > 0) {
        b++;
        x--;
        if (b == n) break;
      } else
        break;
    }
    cout << abs(b - a) << "\n";
  }
}
