#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5, maxm = 1e5 + 5;
const int mod = 1e9 + 7, inf = 0x7f7f7f7f;
long long q, n, T, a, b;
map<int, vector<int> > m;
int p[maxn], t[maxn];
int main() {
  scanf("%lld", &q);
  while (q--) {
    scanf("%lld%lld%lld%lld", &n, &T, &a, &b);
    m.clear();
    int cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &p[i]);
      if (p[i] == 0)
        cnt1++;
      else
        cnt2++;
    }
    for (int i = 1; i <= n; ++i) scanf("%d", &t[i]);
    for (int i = 1; i <= n; ++i) m[t[i]].push_back(p[i]);
    long long sum = 0;
    long long cnt = 0, ans = 0;
    for (auto i : m) {
      int tt = i.first;
      if (sum <= tt - 1) {
        int rr = tt - 1 - sum;
        long long res = 0;
        if (rr >= cnt1 * a) {
          res += cnt1;
          rr -= cnt1 * a;
        } else {
          res += rr / a;
          rr -= rr / a * a;
        }
        if (rr >= cnt2 * b) {
          res += cnt2;
          rr -= cnt2 * b;
        } else {
          res += rr / b;
        }
        res += cnt;
        ans = max(ans, res);
      }
      auto vec = i.second;
      for (auto x : vec)
        if (x == 0)
          sum += a, cnt1--;
        else
          sum += b, cnt2--;
      cnt += vec.size();
    }
    if (sum <= T) ans = max(ans, cnt);
    printf("%lld\n", ans);
  }
  return 0;
}
