#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
void print(T1 a[], T2 n) {
  for (T2 i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
template <class T1, class T2>
void print(vector<T1> a, T2 n) {
  for (T2 i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
long long int modexpo(long long int a, long long int b, long long int m) {
  if (b == 0) {
    return 1;
  } else if (a == 1) {
    return 1;
  }
  if (b % 2 == 0) {
    long long int t = modexpo(a, b / 2, m);
    t = (t * t) % m;
    return t;
  } else {
    long long int t = modexpo(a, b / 2, m);
    t = (t * t) % m;
    t = (t * a) % m;
    return t;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int cntTest;
  cin >> cntTest;
  for (int test = 0; test < cntTest; test++) {
    long long int n, t, a, b;
    cin >> n >> t >> a >> b;
    vector<pair<long long int, long long int>> v;
    vector<int> hard(n);
    int cntA = 0, cntB = 0;
    for (int i = 0; i < n; i++) {
      cin >> hard[i];
      if (hard[i]) {
        cntB++;
      } else {
        cntA++;
      }
    }
    for (int i = 0; i < n; i++) {
      long long int time;
      cin >> time;
      v.push_back({time, hard[i]});
    }
    v.push_back({t + 1, 0});
    sort(v.begin(), v.end());
    long long int cnt1 = 0, cnt2 = 0;
    long long int ans = 0;
    for (int i = 0; i <= n; i++) {
      long long int need = cnt1 * a + cnt2 * b;
      long long int has = v[i].first - 1 - need;
      if (has >= 0) {
        long long int canA = min((cntA - cnt1), has / a);
        has -= canA * a;
        long long int canB = min((cntB - cnt2), has / b);
        ans = max(ans, cnt1 + cnt2 + canA + canB);
      }
      if (v[i].second) {
        cnt2++;
      } else {
        cnt1++;
      }
    }
    cout << ans << "\n";
  }
}
