#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  long long n, k = 0, t = 0, sum = 0, neg = 0, mx = -1000000007,
               mn = 1000000007;
  cin >> n;
  vector<long long> v(n), pos, arr;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> t;
    if (!t) {
      arr.push_back(v[i]);
      sum += v[i];
      if (v[i] < 0) neg++;
    }
    pos.push_back(t);
  }
  sort((arr).begin(), (arr).end());
  if (1) {
    t = arr.size();
    for (int i = 0; i < n; i++) {
      if (pos[i])
        cout << v[i] << " ";
      else
        t--, cout << arr[t] << " ";
    }
  }
  cout << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, tests = 1, prev = 0, i = 0;
  cin >> tests;
  while (tests--) {
    solve();
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  std::mt19937_64 rng(
      std::chrono::steady_clock::now().time_since_epoch().count());
  return 0;
}
