#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
const double PI = 3.141592653589793;
int ans = 0;
void solve(){
ans = 0;
int n, m;
cin >> n >> m;
int a[n];
int c[n];
vector <int> w;
w.pb(0);
int l[m+1];
for(int i = 0; i <= m; i++)
l[i] = 0;
for(int i = 0; i < n; i++)
cin >> a[i];
for(int i = 0; i < n; i++)
cin >> c[i];
for(int i = 0; i < n; i++){
for(int j = 0; j < c[i]; j++){
vector <int> y;
for(int q = 0; q < w.size(); q++){
if(w[q] + a[i] <= m and l[w[q] + a[i]] == 0){
l[w[q] + a[i]] = 1;
y.pb(w[q] + a[i]);
}
}
for(int q = 0; q < y.size(); q++){
w.pb(y[q]);
}
}
}
ans = w.size() - 1;
}
int main() {
fast;
int t;
cin >> t;
for(int i = 0; i < t; i++){
solve();
cout << "Case " << i + 1 << ": " << ans << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiAgICAgCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAgICAgCiNkZWZpbmUgZmFzdCBpb3M6OnN5bmNfd2l0aF9zdGRpbygwKTtjaW4udGllKDApO2NvdXQudGllKDApCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiAgICAKY29uc3QgZG91YmxlIFBJID0gMy4xNDE1OTI2NTM1ODk3OTM7CiAKaW50IGFucyA9IDA7Cgp2b2lkIHNvbHZlKCl7CglhbnMgPSAwOwoJaW50IG4sIG07CgljaW4gPj4gbiA+PiBtOwoJaW50IGFbbl07CglpbnQgY1tuXTsKICAgICAgICB2ZWN0b3IgPGludD4gdzsKICAgICAgICB3LnBiKDApOwogICAgICAgIGludCBsW20rMV07CiAgICAgICAgZm9yKGludCBpID0gMDsgaSA8PSBtOyBpKyspCiAgICAgICAgICAgIGxbaV0gPSAwOwoJZm9yKGludCBpID0gMDsgaSA8IG47IGkrKykKICAgICAgICAgICAgY2luID4+IGFbaV07Cglmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQogICAgICAgICAgICBjaW4gPj4gY1tpXTsKCWZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspewogICAgICAgICAgICBmb3IoaW50IGogPSAwOyBqIDwgY1tpXTsgaisrKXsKICAgICAgICAgICAgICAgIHZlY3RvciA8aW50PiB5OwogICAgICAgICAgICAgICAgZm9yKGludCBxID0gMDsgcSA8IHcuc2l6ZSgpOyBxKyspewogICAgICAgICAgICAgICAgICAgIGlmKHdbcV0gKyBhW2ldIDw9IG0gYW5kICBsW3dbcV0gKyBhW2ldXSA9PSAwKXsKICAgICAgICAgICAgICAgICAgICAgICAgbFt3W3FdICsgYVtpXV0gPSAxOwogICAgICAgICAgICAgICAgICAgICAgICB5LnBiKHdbcV0gKyBhW2ldKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmb3IoaW50IHEgPSAwOyBxIDwgeS5zaXplKCk7IHErKyl7CiAgICAgICAgICAgICAgICAgICAgdy5wYih5W3FdKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICAKICAgICAgICB9CglhbnMgPSB3LnNpemUoKSAtIDE7Cn0KaW50IG1haW4oKSB7CiAgICBmYXN0OwogICAgaW50IHQ7CiAgICBjaW4gPj4gdDsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCB0OyBpKyspewogICAgICAgIHNvbHZlKCk7CiAgICAgICAgY291dCA8PCAiQ2FzZSAiIDw8IGkgKyAxIDw8ICI6ICIgPDwgYW5zIDw8IGVuZGw7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==