#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
struct P {
  int h, t;
  bool operator<(const P B) const { return t < B.t; }
} p[MAX];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, tot, a, b, X = 0, Y = 0, sum = 0, res = 0;
    scanf("%d%d%d%d", &n, &tot, &a, &b);
    for (int i = 0; i < n; i++) {
      scanf("%d", &p[i].h);
      if (p[i].h)
        Y++;
      else
        X++;
    }
    for (int i = 0; i < n; i++) scanf("%d", &p[i].t);
    sort(p, p + n);
    p[n].t = tot + 1;
    for (int i = 0; i <= n; i++) {
      int y = sum, x = i - sum;
      sum += p[i].h;
      if (p[i].t - 1 > tot) break;
      long long curt = p[i].t - 1 - x * 1ll * a - y * 1ll * b;
      int ans = x + y;
      if (curt < 0) continue;
      int rx = X - x, ry = Y - y;
      x = curt / a;
      ans += min(x, rx);
      curt -= min(x, rx) * a;
      y = curt / b;
      ans += min(y, ry);
      res = max(res, ans);
    }
    printf("%d\n", res);
  }
}
