#include<bits/stdc++.h>
using namespace std;
signed main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,m,a,b;
		cin>>n>>m>>a>>b;
		int x=(a<b)? (b-2):(n-b-1);
		int ans=0;
		int u=(int)fabs(a-b)-1;
		int s;
		map <int,int> cnt;
		for(int i=0;i<m;i++)
		{
			cin>>s;
			if(s<=x && cnt[s]<x-s+1)
			{
				cnt[s]++;
			}
		}
		if(cnt.size()==0)
		{
			cout<<0<<endl;
			continue;
		}
		map <int,int> :: iterator it=cnt.begin();
		int rem=x;
		while(it!=cnt.end() && ans<=u && rem>0)
		{
			ans=ans+min(rem,it->second);
			rem=rem-min(rem,it->second);
			rem=min(rem,x-it->first+1-it->second);
			it++;
		}
		ans=min(ans,u);
		cout<<ans<<endl;
	}
}