#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 200100;
const int M = 1e9 + 7;
int n, m, k, t, x, y;
long long sum[maxn];
struct node {
  long long ty, t;
} a[maxn];
bool cmp(node a, node b) { return a.t < b.t; }
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    scanf("%d", &m);
    scanf("%d", &x);
    scanf("%d", &y);
    for (int i = 0; i < n; i++) {
      cin >> a[i].ty;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i].t;
    }
    sort(a, a + n, cmp);
    a[n].t = m + 1;
    long long time = 0;
    int res = 0;
    for (int i = n - 1; i >= 0; i--) {
      sum[i] = res;
      if (a[i].ty == 0) res++;
    }
    int ans = 0;
    if (a[0].t) ans = min((a[0].t - 1) / x, sum[0]);
    res = 0;
    for (int i = 0; i < n; i++) {
      if (a[i].ty == 0)
        time += x;
      else
        time += y;
      if (time < a[i + 1].t) {
        res = i + 1;
        res += min((a[i + 1].t - time - 1) / x, sum[i]);
        ans = max(ans, res);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
