#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;
    printf("%d\n",
           abs(a - b) + min(x, abs(min(a, b) - 1) + abs(n - max(a, b))));
  }
}
