#include <bits/stdc++.h>
using namespace std;
int b[10];
struct node {
  long long val, time;
} a[200000 + 10];
bool cmp(node a, node c) {
  return a.time < c.time || (a.time == c.time && (b[a.val] < b[c.val]));
}
long long num = 0, num1 = 0, sum = 0, sum1 = 0;
long long check(long long T) {
  if (b[0] < b[1]) {
    if (num * b[0] + sum1 * b[1] >= T) {
      return (T - sum1 * b[1]) / b[0] + sum1;
    } else {
      return (T - num * b[0]) / b[1] + num;
    }
  } else {
    if (sum * b[0] + num1 * b[1] >= T) {
      return (T - sum * b[0]) / b[1] + sum;
    } else {
      return (T - num1 * b[1]) / b[0] + num1;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    num = 0, num1 = 0, sum = 0, sum1 = 0;
    long long n, t;
    cin >> n >> t >> b[0] >> b[1];
    for (int i = (1); i < (n + 1); i++) {
      cin >> a[i].val;
      if (a[i].val == 0)
        num++;
      else
        num1++;
    }
    for (int i = (1); i < (n + 1); i++) {
      cin >> a[i].time;
    }
    sort(a + 1, a + 1 + n, cmp);
    long long now = 0;
    int ans = 0;
    for (int i = (1); i < (n + 1); i++) {
      if (now > t) break;
      if (now < a[i].time) {
        ans = max(ans, i - 1);
        int tt = min(t, a[i].time - 1);
        ans = max(ans, (int)check(tt));
        ans = min(ans, (int)n);
      }
      now += b[a[i].val];
      if (a[i].val == 0)
        sum++;
      else
        sum1++;
    }
    if (num * b[0] + num1 * b[1] <= t) ans = n;
    cout << ans << "\n";
  }
  return 0;
}
