#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, e, f, g, h, i, j, k;
  cin >> a;
  for (i = 0; i < a; i++) {
    cin >> b >> c >> d >> e;
    f = (d > e ? d : e);
    g = (d > e ? e : d);
    if (c == 0) {
      cout << f - g << "\n";
    } else {
      if (f + c >= b) {
        c = c - (b - f);
        g = g - 1, f = b;
        if (g < c) {
          g = 1;
        } else {
          g = g + 1 - c;
        }
        cout << f - g << "\n";
      } else {
        f += c;
        cout << f - g << "\n";
      }
    }
  }
  return 0;
}
