#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
struct Problem {
  int type;
  long long time;
};
Problem pr[MAXN];
bool cmp(Problem a, Problem b) { return a.time < b.time; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long m, n, t, a, b, ti, easy, e, hard, h, ans, s;
  cin >> m;
  for (int test = 0; test < m; test++) {
    cin >> n >> t >> a >> b;
    easy = 0;
    for (int i = 0; i < n; i++) {
      cin >> pr[i].type;
      if (!pr[i].type) easy++;
    }
    hard = n - easy;
    for (int i = 0; i < n; i++) cin >> pr[i].time;
    if (easy * a + hard * b <= t) {
      cout << n << '\n';
      ;
      continue;
    }
    sort(pr, pr + n, cmp);
    ti = ans = e = h = 0;
    for (int i = 0; i < n; i++) {
      if (pr[i].time > ti) {
        s = i;
        if (ti + (easy - e) * a < pr[i].time) {
          s += (easy - e);
          if (ti + (easy - e) * a + (hard - h) * b < pr[i].time)
            s += (hard - h);
          else
            s += (pr[i].time - 1 - (easy - e) * a - ti) / b;
        } else
          s += (pr[i].time - 1 - ti) / a;
        ans = max(s, ans);
      }
      if (pr[i].type == 0) {
        ti += a;
        e++;
      } else {
        ti += b;
        h++;
      }
    }
    cout << ans << '\n';
    ;
  }
  return 0;
}
