#include <bits/stdc++.h>
using namespace std;
void run() {
  long long n;
  cin >> n;
  vector<long long> a;
  vector<long long> used;
  for (long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    a.push_back(x);
  }
  vector<long long> mass;
  for (long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    used.push_back(x);
    if (!x) mass.push_back(a[i]);
  }
  sort(mass.rbegin(), mass.rend());
  long long uk = 0;
  for (long long i = 0; i < n; ++i) {
    if (!used[i]) {
      cout << mass[uk] << ' ';
      ++uk;
    } else {
      cout << a[i] << ' ';
    }
  }
  cout << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) run();
  return 0;
}
