#include<bits/stdc++.h>
#define dbg1(x)     cerr<<#x<<':'<<x<<'\n'
#define dbg2(x,y)   cerr<<#x<<':'<<x<<','<<#y<<':'<<y<<'\n'
#define dbg3(x,y,z) cerr<<#x<<':'<<x<<','<<#y<<':'<<y<<','<<#z<<':'<<z<<'\n'
using namespace std;
typedef long long ll;

template <class T>  /// <--- layering the gcd
T gcd(T a,T b){
  if(a == 0 or b == 0) return 0;
  return __gcd(a,b);
}

const int N = 350;
int n,m,x,y;
int seq[N];

ll cache[N][N][2];
bool vis[N][N][2];

ll dp(int l,int rem,int end){
  ll &ans = cache[l][rem][end];
  if(vis[l][rem][end]) return ans;
  ans = 0;
  vis[l][rem][end] = true;
  /// base cases check order


  ll num = 0;

  if(l >= n) return 0; /// if the last separator was placed at the end of the array

  if(end){ /// if we can end the array here
  	int digits = n-l;  /// number of digits remaining
  	if(digits == 0 or digits > m) return 0;
  	for(int i=1;i<=digits;i++) /// calculate the remaining number
  	  num = num*10 + seq[l+i];
  	ans = num;
  	//dbg3(l,rem,end);
	//dbg1(ans);
	return ans;
  }

  for(int i=1;i<=m and l+i<=n ;i++) /// while reading m digits till end of array
    {
      num = num*10 + seq[l+i];
      ans = max(ans , gcd(num,dp(l+i,rem-1,(rem-1) == 0)));  /// place separator at l+i position, dec. rem,if rem becomes zero terminate

      if(y-x >= rem-1)            /// if we already have used x separators
      ans = max(ans,gcd(num,dp(l+i,rem-1,1))); /// place separator at l+i position at terminate the sequence with end = 1

  }
  return ans;
}


int main(){

//  freopen("in.txt","r",stdin);
//  freopen("err.txt","w",stderr);
  string str;
  int t; cin>>t;
  while(t--){
    memset(vis,0,sizeof vis);
    cin>>n; // size of seq.
    cin>>str;

    for(int i=0;i<(int)str.size();i++)
      seq[i+1] = str[i]-'0';

    cin>>m>>x>>y;
    ll ans = dp(0,y,0);

	cout<<ans<<'\n';
 }

}
