#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long m, n, t, a1, b1, cnta, cntb, b[maxn];
struct point {
  long long x, y;
  point(long long x = 0, long long y = 0) : x(x), y(y) {}
  bool operator<(const point& p) const {
    return x < p.x || (x == p.x && y < p.y);
  }
} a[maxn];
int main() {
  cin >> m;
  while (m--) {
    cnta = cntb = 0;
    cin >> n >> t >> a1 >> b1;
    for (long long i = 1; i <= n; i++) {
      cin >> b[i];
      if (b[i])
        cntb++;
      else
        cnta++;
    }
    for (long long i = 1; i <= n; i++) {
      long long x;
      cin >> x;
      a[i] = point(x, b[i]);
    }
    a[n + 1] = point(t + 1, 0);
    sort(a + 1, a + n + 2);
    long long ans = 0, cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n + 1; i++) {
      long long sum = cnt1 * a1 + cnt2 * b1, res = a[i].x - sum - 1;
      if (res >= 0) {
        long long ta = min(cnta - cnt1, res / a1);
        res -= ta * a1;
        long long tb = min(cntb - cnt2, res / b1);
        ans = max(ans, cnt1 + cnt2 + ta + tb);
      }
      long long cnt = i;
      while (cnt <= n + 1 && a[cnt].x == a[i].x) {
        if (a[cnt].y)
          cnt2++;
        else
          cnt1++;
        cnt++;
      }
      i = cnt - 1;
    }
    cout << ans << endl;
  }
  return 0;
}
