#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 4;
int n, T, a, b;
int cnta, cntb;
vector<pair<int, int> > prob;
void read() {
  prob.clear();
  cnta = 0;
  cntb = 0;
  cin >> n >> T >> a >> b;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (x) {
      ++cntb;
    } else {
      ++cnta;
    }
    prob.push_back({0, x});
  }
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    prob[i].first = x;
  }
  sort(prob.begin(), prob.end());
}
long long calc(long long tm) {
  if (tm < 0 || (cnta == 0 && cntb == 0)) {
    return 0;
  }
  if (cnta == 0) {
    return min((long long)cntb, tm / (long long)b);
  }
  if (cntb == 0) {
    return min((long long)cnta, tm / (long long)a);
  }
  long long fr = min((long long)cnta, tm / (long long)a);
  tm -= (long long)a * fr;
  long long sc = min((long long)cntb, tm / (long long)b);
  return fr + sc;
}
void solve() {
  read();
  long long sumTime = 0, mx = 0;
  long long done = 0;
  int it = 0;
  while (it < n) {
    long long tm = prob[it].first - 1 - sumTime;
    if (tm >= 0) {
      mx = max(mx, done + calc(tm));
    }
    int tmp = prob[it].first;
    while (it < n && prob[it].first == tmp) {
      if (prob[it].second) {
        --cntb;
        sumTime += b;
      } else {
        --cnta;
        sumTime += a;
      }
      ++done;
      ++it;
    }
    tm = tmp - sumTime;
    if (tm >= 0) {
      mx = max(mx, done + calc(tm));
    }
  }
  if ((long long)T - sumTime >= 0) {
    mx = max(mx, done);
  }
  cout << mx << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    solve();
  }
  return 0;
}
