#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
#define cauto const auto
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

struct edge{int to;};
using graph = vector<vector<edge>>;

constexpr auto dbg = false;

const int INF = 1031231234;

int32_t main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  int T;
  cin >> T;
  while(T--) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    --a, --b;

    if (a > b) {
      a = n - a - 1;
      b = n - b - 1;
    }
    
    vi t(m);
    trav(i, t) cin >> i;
    sort(all(t));

    auto check = [&](int k) {
                   assert(k >= 0 and k <= m);
                   auto mx = -INF;
                   for (int i = k - 1, it = 1; i >= 0; i--, it++) {
                     mx = max(mx, t[i] + it);
                   }
                   return mx <= b;
                 };

    auto dist = abs(a - b);
    if (dist <= 1) {
      cout << 0 << '\n';
    } else {
      int lo = 0, hi = min(m, dist - 1);
      while (lo < hi) {
        auto mid = lo + (hi - lo + 1) / 2;
        auto feas = check(mid);
        if (feas) {
          lo = mid;
        } else {
          hi = mid - 1;
        }
      }
      cout << lo << '\n';
    }
  }
}
