#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';
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBkYmcxKHgpICAgICBjZXJyPDwjeDw8JzonPDx4PDwnXG4nCiNkZWZpbmUgZGJnMih4LHkpICAgY2Vycjw8I3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