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