#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 front = (a > b) ? b : a;
    int last = (a > b) ? a : b;
    for (int i = 0; i < x;) {
      if (front != 1) {
        front--;
        i++;
      }
      if (i < x) {
        if (last != n) {
          last++;
          i++;
        }
      }
      if (front == 1 && last == n) {
        break;
      }
    }
    cout << (last - front) << endl;
  }
}
