#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, etime, cnt[2], f[2];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d%d%d", &n, &etime, f, f + 1);
    vector<int> v = {etime};
    vector<pair<int, bool> > p(n);
    cnt[0] = cnt[1] = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &p[i].second);
      cnt[p[i].second]++;
    }
    for (int i = 0; i < n; i++) {
      scanf("%d", &p[i].first);
      v.push_back(p[i].first - 1);
    }
    sort(p.begin(), p.end());
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    int mx = 0, must_cnt = 0, i = 0;
    long long must = 0;
    for (int x : v) {
      while (i < p.size() && p[i].first <= x) {
        cnt[p[i].second]--;
        must_cnt++;
        must += f[p[i].second];
        i++;
      }
      if (x >= must) {
        int max_points = must_cnt, rem = x - must;
        for (int j = 0; j < 2; j++) {
          int take = min(cnt[j], rem / f[j]);
          rem -= take * f[j];
          max_points += take;
        }
        mx = max(mx, max_points);
      }
    }
    printf("%d\n", mx);
  }
}
