text: #include <bits/stdc++.h>
  
  #define sd(x) scanf("%d",&x)
  #define sd2(x,y) scanf("%d%d",&x,&y)
  #define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
  
  #define fi first
  #define se second
  #define pb push_back
  #define mp make_pair
  #define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
  
  #define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  #define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
  
  #define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
  
  using namespace std;
  
  typedef long long ll;
  typedef long double ld;
  typedef pair<int,int> pii;
  
  template<typename S, typename T> 
  ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}
  
  template<typename T>
  ostream& operator<<(ostream& out,vector<T> const& v){
  int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
  
  template<typename T>
  void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
  
  template<typename T, typename... Args>
  void trace(const char* names, T&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
  
  const ld PI = 3.1415926535897932384626433832795;
  
  const int N = 100100;
  
  ll n, l, a, b;
  ll s[N];
  
  ll getcost(ll m){
  	ll cost = 0;
  	for(int i = 1; i <= n; i++){
  		cost += abs(m + l * (i-1) - s[i]);
  	}
  	return cost;
  }
  
  void solve(){
  	cin >> n >> l >> a >> b;
  	
  	for(int i = 1; i <= n; i++){
  		cin >> s[i];
  	}
  	
  	sort(s+1, s+1+n);
  	
  	ll lo = a, hi = b - l * n + 1, m1, m2;
  	
  	while(hi - lo > 4){
  		m1 = (lo + hi) / 2;
  		m2 = m1 + 1;
  		
  		ll cost1 = getcost(m1);
  		ll cost2 = getcost(m2);
  		
  		if(cost1 <= cost2) hi = m2;
  		else lo = m1 + 1;
  	}
  	
  	ll ans = 1ll << 60;
  	for(int i = lo; i < hi; i++){
  		ans = min(ans, getcost(i));
  	}
  	
  	cout << ans << endl;
  	
  }
  
  int main(){ _
  	int t;
  	cin >> t;
  	while(t--) solve();
  	return 0;
  }
  