#include <bits/stdc++.h>
using namespace std;
int n, t, x, a, b;
vector<vector<int>> g;
vector<int> used;
vector<int> used_left;
vector<int> mt;
vector<int> p_mt;
int comp = 0;
int main() {
  cin >> t;
  for (int i = 0; i < t; ++i) {
    cin >> n >> x >> a >> b;
    if (a > b) {
      swap(a, b);
    }
    while (a > 1 && x > 0) {
      a--;
      x--;
    }
    while (b < n && x > 0) {
      b++;
      x--;
    }
    cout << b - a << endl;
  }
}
