#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t, n, a, b, x, ans;
  cin >> t;
  while (t--) {
    cin >> n >> x >> a >> b;
    if (a > b) swap(a, b);
    if (a - x < 1) {
      int aux = a;
      a = 1;
      x -= (aux - 1);
    } else {
      a -= x;
      x = 0;
    }
    if (b + x > n)
      b = n;
    else
      b += x;
    cout << b - a << '\n';
  }
}
