#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6;
const long long MX = -1e7 - 3;
const long long MN = 1e7 + 3;
long long n, m, cnt, ans, x, y, mx = MX, mn = MN, a, b, c, d, T, l, r, k;
float p = 3.14159;
bool bl, bl1;
string str = "", s;
map<char, long long> mp, mp1;
vector<long long> v;
deque<long long> q;
bool used[N];
pair<long long, long long> pr[N];
pair<long long, char> pr1[N];
int main() {
  cin >> T;
  for (long long i = 0; i < T; i++) {
    cin >> n >> x >> a >> b;
    if (a > b) {
      c = a;
      a = b;
      b = c;
    }
    if (a - x >= 1) {
      a -= x;
      x = 0;
    } else {
      x -= a - 1;
      a = 1;
    }
    if (b + x <= n) {
      b += x;
      x = 0;
    } else
      b = n;
    v.push_back(b - a);
  }
  for (long long i = 0; i < v.size(); i++) cout << v[i] << "\n";
  cout << "\n";
  return 0;
}
