#include <bits/stdc++.h>
using namespace std;
struct Problem {
  bool type;
  int end_time;
  int cost_time;
};
Problem problems[200010];
bool cmp(Problem a, Problem b) {
  if (a.end_time != b.end_time)
    return a.end_time < b.end_time;
  else
    return a.cost_time < b.cost_time;
}
int main() {
  int m;
  cin >> m;
  while (m--) {
    int n, T, a, b;
    cin >> n >> T >> a >> b;
    int num_a = 0;
    for (int i = 1; i <= n; i++) {
      cin >> problems[i].type;
      if (problems[i].type)
        problems[i].cost_time = b;
      else {
        problems[i].cost_time = a;
        num_a++;
      }
    }
    for (int i = 1; i <= n; i++) {
      cin >> problems[i].end_time;
    }
    sort(problems + 1, problems + n + 1, cmp);
    problems[n + 1].end_time = T + 1;
    long long cur_T = 0;
    int score = 0;
    for (int i = 0; i <= n; i++) {
      if (!problems[i + 1].type && num_a > 0) num_a--;
      if (cur_T < problems[i + 1].end_time) {
        int diff = problems[i + 1].end_time - cur_T - 1;
        score = max(score, i + min(static_cast<int>(diff / a), num_a));
      }
      cur_T += problems[i + 1].cost_time;
    }
    cout << score << endl;
  }
  return 0;
}
