#include <bits/stdc++.h>
using namespace std;
const int maxn = 200100;
int n, m, k, t, x, y;
long long sum[maxn];
struct node {
  long long ty, ti;
} a[maxn];
bool cmp(node a, node b) { return a.ti < b.ti; }
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> m >> x >> y;
    for (int i = 0; i < n; i++) cin >> a[i].ty;
    for (int i = 0; i < n; i++) cin >> a[i].ti;
    sort(a, a + n, cmp);
    a[n].ti = 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].ti) ans = min((a[0].ti - 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].ti) {
        res = i + 1;
        res += min((a[i + 1].ti - time - 1) / x, sum[i]);
        ans = max(ans, res);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
