#include <bits/stdc++.h>

#define debug(...)  fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define rep(i,x,y) for(int i=(x);i<=(y);++i)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;

const ll MOD=1e9+7;

ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1) {if(b&1) ret=ret*a%MOD;a=a*a%MOD;} return ret;}
const int MAXN = 2e5 + 10;

int m;
ll n,a,b;

ll s[MAXN];

int main(){
    int T;
    cin >> T;
    while(T--){
        scanf("%lld%d%lld%lld",&n,&m,&a,&b);
        rep(i,1,m){
            scanf("%lld", s + i);
        }
        s[m + 1] = 0x3f3f3f3f;
        sort(s + 1, s + 1 + m);
        ll re = 0, ss = 0;
        if(a > b) re = (n - b);
        else re = (b - 1);
        ss = abs(a - b) - 1;
        // ll ans = 0;
        int idx = lower_bound(s + 1,s + 1 + m, re) - s - 1;
        ll ans = 0;
        for(int i = idx; i >= 1; --i){
            if(s[i] < re)   ans++,--re;
        }   
        cout << min(ans,ss) << '\n';
    }
    return 0;
}

/*
3
7 2 3 6
1 4
7 2 3 6
5 1
7 2 3 6
4 4
*/