#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, d;
    cin >> n >> x >> a >> b;
    if (x == 0) {
      cout << abs(a - b) << endl;
    } else if (n == 2) {
      cout << abs(a - b) << endl;
    } else {
      if (a >= b) {
        while (x > 0 && b > 1) {
          b--;
          x--;
        }
        if (x > 0) {
          while (x > 0 && a < n) {
            a++;
            x--;
          }
        }
        cout << abs(a - b) << endl;
      } else if (b >= a) {
        while (x > 0 && b < n) {
          b++;
          x--;
        }
        if (x > 0) {
          while (x > 0 && a > 1) {
            a--;
            x--;
          }
        }
        cout << abs(a - b) << endl;
      }
    }
  }
}
