#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
struct node {
  int dif;
  long long need;
  bool operator<(const node &f) const {
    if (f.need != need)
      return f.need > need;
    else
      return f.dif > dif;
  }
} pro[M];
long long ans[M];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    memset(ans, 0, sizeof(ans));
    long long n, t, a, b;
    scanf("%lld%lld%lld%lld", &n, &t, &a, &b);
    long long simple = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &pro[i].dif);
      if (!pro[i].dif) simple++;
    }
    for (int i = 1; i <= n; i++) scanf("%lld", &pro[i].need);
    sort(pro + 1, pro + n + 1);
    long long time = 0;
    if (pro[1].need) ans[0] = min(simple, (pro[1].need - 1) / a);
    for (int i = 1; i <= n; i++) {
      if (pro[i].dif)
        time += b;
      else
        simple--, time += a;
      if (simple == 0 || i == n) break;
      ans[i] = min(simple, (pro[i + 1].need - time - 1) / a);
    }
    time = 0;
    long long cnt = ans[0];
    for (int i = 1; i <= n; i++) {
      time += pro[i].dif == 0 ? a : b;
      if (time > t)
        break;
      else {
        if (time < pro[i + 1].need || i == n) {
          cnt = max(cnt, i + ans[i]);
        }
      }
    }
    printf("%lld\n", cnt);
  }
  return 0;
}
