#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
int main() {
  int t;
  cin >> t;
  for (int k = 0; k < t; k++) {
    int n;
    long long int m, a, b, na, nb;
    cin >> n >> m >> a >> b;
    vector<long long int> ar;
    vector<pair<long long int, long long int>> p;
    na = nb = 0;
    for (int i = 0; i < n; i++) {
      long long int x;
      cin >> x;
      ar.push_back(x);
      if (x == 0)
        na++;
      else
        nb++;
    }
    for (int i = 0; i < n; i++) {
      long long int x;
      cin >> x;
      p.push_back(make_pair(x, ar[i]));
    }
    sort(p.begin(), p.end());
    long long int tt = 0;
    int count = 0;
    int i = 0;
    vector<pair<int, int>> cal;
    while (tt <= m && i < n - 1) {
      int par = p[i].second;
      if (par == 0)
        tt += a;
      else
        tt += b;
      count++;
      if (tt < p[i + 1].first)
        cal.push_back(make_pair(count, tt));
      else
        cal.push_back(make_pair(0, tt));
      i++;
    }
    if (i == n - 1) {
      int par = p[i].second;
      if (par == 0)
        tt += a;
      else
        tt += b;
      count++;
      if (tt <= m)
        cal.push_back(make_pair(count, tt));
      else
        cal.push_back(make_pair(0, tt));
      i++;
    }
    int num = 0;
    vector<int> cost(n);
    int temp, tl, add, extra;
    tl = p[0].first - 1;
    if (tl < 0) tl = 0;
    add = min(tl / a, na);
    tl = tl - add * a;
    extra = min(tl / b, nb);
    temp = add + extra;
    num = temp;
    for (int j = 0; j < i - 1; j++) {
      if (p[j].second == 0)
        na--;
      else
        nb--;
      tl = p[j + 1].first - cal[j].second - 1;
      if (tl < 0) tl = 0;
      add = min(tl / a, na);
      tl = tl - add * a;
      extra = min(tl / b, nb);
      temp = cal[j].first + add + extra;
      if (num < temp) num = temp;
      cost[j] = num;
    }
    cost[i - 1] = cal[i - 1].first;
    if (num < cost[i - 1]) num = cost[i - 1];
    cout << num << endl;
  }
}
