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