#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu unsigned long long int
#define max3(a,b,c) max(a,max(b,c))
double PI=acos(-1.0);
ll ans22=0;
int dp[1005][1005][2];
int x,y;
int n;
vector<int> a(1005);
vector<int> b(1005);
// dp denotes what is the minimum cost to transform the array a starting
// at "index" with last 0 or 1 placed at "lindex" uptil "index-1"
// ie if we have transform array like 1 1 1 0 0 0 0
// we are at index 7 (0 indexing) then our dp state will be like dp(7,3,0) ie we placed 0 from index 3-6
int fun(int index,int lindex,int f)
{
if(index==n)
{
if(n-lindex>=x && n-lindex<=y)return 0;
else return 1e8;
}
int &res=dp[index][lindex][f];
if(res!=-1)
return res;
res=1e8;
if(f==0){
int cost=(a[index]==0)?0:b[index]; //placing 0 at "index" and check if we need to flip or not,if yes cost=b[index]
int pos1=index-lindex+1; //we calculated the size of subarray ending at "index" which contains only 0
if(pos1>=x && pos1<=y)res=min(res,cost+fun(index+1,lindex,0));//if size of this subarray fits the criteria we can put 0 at this index
pos1=index-lindex; //we calculated the size of subarray ending at "index-1" which contains only 0
cost=(a[index]==1)?0:b[index]; //placing 1 at "index" and check if we need to flip or not,if yes cost=b[index]
if(pos1>=x && pos1<=y)
res=min(res,cost+fun(index+1,index,1));//if size of this subarray fits the criteria we can put 1 at this index
}else{//same as above
int cost=(a[index]==0)?0:b[index];
int pos1=index-lindex; //we calculated the size of subarray ending at "index-1" which contains only 1
if(pos1>=x && pos1<=y)
res=min(res,cost+fun(index+1,index,0));//if size of this subarray fits the criteria we can put 0 at this index
pos1=index-lindex+1; //we calculated the size of subarray ending at "index" which contains only 1
cost=(a[index]==1)?0:b[index];
if(pos1>=x && pos1<=y)res=min(res,cost+fun(index+1,lindex,1));//placing 1 after checking criteria
}
return res;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n); //input n
scanf("%d%d",&x,&y); //input x y
for(int i=0;i<n;i++)
scanf("%d",&a[i]); //input A
for(int i=0;i<n;i++)
scanf("%d",&b[i]); //input B
memset(dp,-1,sizeof dp);
int ans=1e8;
int cost=(a[0]==0)?0:b[0]; //placing 0 at first index and check if we need to flip or not,if yes cost=b[0]
ans=min(ans,cost+fun(1,0,0));
cost=(a[0]==1)?0:b[0]; //placing 1 at first index and check if we need to flip or not,if yes cost=b[0]
ans=min(ans,cost+fun(1,0,1));
printf("%d\n",ans);
}
return 0;
}
I3ByYWdtYSBHQ0Mgb3B0aW1pemUoIk8zIikKI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcgaW50CiNkZWZpbmUgbGx1IHVuc2lnbmVkIGxvbmcgbG9uZyBpbnQKI2RlZmluZSBtYXgzKGEsYixjKSBtYXgoYSxtYXgoYixjKSkKZG91YmxlIFBJPWFjb3MoLTEuMCk7CmxsIGFuczIyPTA7CmludCBkcFsxMDA1XVsxMDA1XVsyXTsKaW50IHgseTsKaW50IG47CnZlY3RvcjxpbnQ+IGEoMTAwNSk7CnZlY3RvcjxpbnQ+IGIoMTAwNSk7Ci8vIGRwIGRlbm90ZXMgd2hhdCBpcyB0aGUgbWluaW11bSBjb3N0IHRvIHRyYW5zZm9ybSB0aGUgYXJyYXkgYSBzdGFydGluZyAKLy8gYXQgImluZGV4IiB3aXRoIGxhc3QgMCBvciAxIHBsYWNlZCBhdCAibGluZGV4IiB1cHRpbCAiaW5kZXgtMSIKLy8gaWUgaWYgd2UgaGF2ZSB0cmFuc2Zvcm0gYXJyYXkgbGlrZSAxIDEgMSAwIDAgMCAwCi8vIHdlIGFyZSBhdCBpbmRleCA3ICgwIGluZGV4aW5nKSB0aGVuIG91ciBkcCBzdGF0ZSB3aWxsIGJlIGxpa2UgZHAoNywzLDApIGllIHdlIHBsYWNlZCAwIGZyb20gaW5kZXggMy02CmludCBmdW4oaW50IGluZGV4LGludCBsaW5kZXgsaW50IGYpCnsKCWlmKGluZGV4PT1uKQoJewoJCWl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