#include <bits/stdc++.h>
using namespace std;
int max_dst(int n, int s, int a, int b) {
  int ans = (a > b) ? (a - b) : (b - a);
  if (n == 2) return 1;
  if (s == 0) return (a > b) ? (a - b) : (b - a);
  if ((a == 1 || b == 1) && (b == n || a == n)) return n - 1;
  if (n - 2 == s) return n - 1;
  return (ans + s);
}
int main() {
  int t, n, s, a, b;
  cin >> t;
  while (t--) {
    cin >> n >> s >> a >> b;
    int k = max_dst(n, s, a, b);
    if (k >= n)
      cout << n - 1 << endl;
    else
      cout << k << endl;
  }
  return 0;
}
