#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
void fastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
pair<int, int> arr[N];
int main() {
  fastIO();
  int T;
  cin >> T;
  while (T--) {
    long long n, t, a, b;
    cin >> n >> t >> a >> b;
    long long x = 0, y = 0;
    for (int i = 0; i < n; ++i) {
      cin >> arr[i].second;
      arr[i].second++;
      x += arr[i].second == 1;
      y += arr[i].second == 2;
    }
    for (int i = 0; i < n; ++i) {
      cin >> arr[i].first;
    }
    sort(arr, arr + n);
    arr[n].first = t + 1;
    long long rem = arr[0].first - 1;
    long long remm = min(rem / a, x);
    rem -= remm * a;
    long long remmm = min(rem / b, y);
    long long ans = max(0ll, remm + remmm);
    long long xx = 0, yy = 0;
    for (int i = 0; i < n; ++i) {
      x -= arr[i].second == 1;
      y -= arr[i].second == 2;
      xx += arr[i].second == 1;
      yy += arr[i].second == 2;
      if (arr[i + 1].first == arr[i].first) continue;
      rem = arr[i + 1].first - 1 - xx * a - yy * b;
      if (rem < 0) continue;
      remm = min(rem / a, x);
      rem -= remm * a;
      remmm = min(rem / b, y);
      ans = max(ans, remm + remmm + i + 1);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
