#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 100;
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int modexp(long long int x, long long int n, long long int mod) {
  long long int result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result % mod * x % mod) % mod;
    x = (x % mod * x % mod) % mod;
  }
  return result;
}
bool vis[N];
vector<long long int> adj[N];
long long int mx = 0;
void DFS(long long int s) {
  vis[s] = true;
  for (int i = 0; i < adj[s].size(); i++)
    if (!vis[adj[s][i]]) DFS(adj[s][i]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, t, a, b;
    cin >> n >> t >> a >> b;
    vector<pair<long long int, long long int>> v;
    vector<long long int> h(n);
    long long int ca = 0, cb = 0;
    for (int i = 0; i < n; ++i) {
      cin >> h[i];
      if (h[i])
        cb++;
      else
        ca++;
    }
    for (int i = 0; i < n; ++i) {
      long long int x;
      cin >> x;
      v.push_back({x, h[i]});
    }
    v.push_back({t + 1, 0});
    sort(v.begin(), v.end());
    long long int c1 = 0, c2 = 0;
    long long int ans = 0;
    for (int i = 0; i <= n; ++i) {
      if (i > 0) {
        if (v[i - 1].second)
          c2++;
        else
          c1++;
      }
      if (v[i].first - 1 >= a * c1 + b * c2) {
        long long int l = v[i].first - 1 - (a * c1 + b * c2);
        long long int l1 = ca - c1;
        long long int l2 = cb - c2;
        long long int sum = c1 + c2;
        if (l1 * a >= l)
          sum += l / a;
        else
          sum += l1 + min(l2, (l - l1 * a) / b);
        ans = max(ans, sum);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
