#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<pair<long long, long long>> v;
  pair<long long, long long> now;
  long long t, n, time, a, b, x, al, bl, nowa, nowb, ng, lol, lolt;
  cin >> t;
  while (t-- > 0) {
    v.clear();
    ng = 0;
    al = 0;
    bl = 0;
    nowa = 0;
    nowb = 0;
    ng = 0;
    cin >> n >> time >> a >> b;
    for (int i = 0; i < n; ++i) {
      cin >> now.second;
      if (now.second)
        ++bl;
      else
        ++al;
      v.push_back(now);
    }
    for (int i = 0; i < n; ++i) cin >> v[i].first;
    v.push_back(make_pair(time + 1, -1));
    v.push_back(make_pair(0, -1));
    sort(v.begin(), v.end());
    for (int i = 0; i < n + 1; ++i) {
      lol = 0;
      lolt = 0;
      if (v[i].second == 1)
        ++nowb;
      else if (v[i].second == 0)
        ++nowa;
      if (v[i].first == v[i + 1].first) continue;
      if (nowa * a + nowb * b > v[i + 1].first - 1) continue;
      lol += nowa + nowb;
      lolt += nowa * a + nowb * b;
      lolt = v[i + 1].first - 1 - lolt;
      x = min(al - nowa, lolt / a);
      lol += x;
      lolt -= x * a;
      x = min(bl - nowb, lolt / b);
      lol += x;
      lolt -= x * b;
      if (lol > ng) ng = lol;
    }
    cout << ng << endl;
  }
  return 0;
}
