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