#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> arr(n), loc(n), neg;
  for (int i = 0; i < n; ++i) cin >> arr[i];
  for (int i = 0; i < n; ++i) cin >> loc[i];
  for (int i = 0; i < n; ++i)
    if (!loc[i]) neg.emplace_back(arr[i]);
  sort(neg.rbegin(), neg.rend());
  int j = 0;
  for (int i = 0; i < n; ++i)
    if (!loc[i])
      cout << neg[j++] << ' ';
    else
      cout << arr[i] << ' ';
  cout << '\n';
}
int main() {
  do {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  } while (0);
  ;
  long long int t;
  cin >> t;
  for (long long int i = 1; i <= t; ++i) {
    if (0) cout << "Case #" << i << ": ";
    solve();
  }
  return 0;
}
