#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int sum = 0;
  vector<int> a(n), state(n), ans(n), nu;
  for (auto& i : a) {
    cin >> i;
    sum += i;
  }
  for (auto& i : state) cin >> i;
  for (int i = 0; i < (n); ++i) {
    if (!state[i]) nu.push_back(a[i]);
  }
  if (sum >= 0)
    sort(begin(nu), end(nu), greater<int>());
  else
    sort(begin(nu), end(nu));
  int index = 0;
  for (int i = 0; i < (n); ++i) {
    if (state[i])
      ans[i] = a[i];
    else {
      ans[i] = nu[index];
      ++index;
    }
  }
  for (auto i : ans) cout << i << ' ';
  cout << '\n';
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) solve();
}
