#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t-- > 0) {
    int n, x, a, b;
    cin >> n >> x >> a >> b;
    int dist = abs(a - b);
    if (a > b) {
      swap(a, b);
    }
    int left = min(a - 1, x);
    dist += left;
    x -= left;
    int right = min(n - b, x);
    dist += right;
    cout << dist << '\n';
  }
  return 0;
}
