#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 2e5 + 7;
int n, T, a, b, cnt[2];
struct node {
  int type, t;
  bool operator<(const node &rhs) const { return t < rhs.t; }
} pro[N];
void Init() {
  memset(cnt, 0, sizeof(cnt));
  scanf("%d%d%d%d", &n, &T, &a, &b);
  for (int i = (1); i < (n + 1); ++i) scanf("%d", &pro[i].type);
  for (int i = (1); i < (n + 1); ++i) scanf("%d", &pro[i].t);
}
int Solve() {
  sort(pro + 1, pro + n + 1);
  pro[n + 1].t = T + 1;
  for (int i = (1); i < (n + 1); ++i) cnt[pro[i].type]++;
  int ans = 0, tot = 0;
  for (int i = (1); i < (n + 2); ++i) {
    int tim = pro[i].t - 1;
    if (tot <= tim) {
      int tmp = i - 1, num, remain = tim - tot;
      int num0 = remain / a;
      num = min(num0, cnt[0]);
      tmp += num;
      remain -= num * a;
      int num1 = remain / b;
      num = min(num1, cnt[1]);
      tmp += num;
      ans = max(ans, tmp);
    }
    tot += pro[i].type ? b : a;
    if (tot > T) break;
    cnt[pro[i].type]--;
  }
  return printf("%d\n", ans);
}
int main() {
  int test;
  scanf("%d", &test);
  while (test--) {
    Init();
    Solve();
  }
  return 0;
}
