#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];
    int l[n];
    for (int i = 0; i < n; ++i) cin >> l[i];
    vector<int> ans;
    for (int i = 0; i < n; ++i) {
      if (!l[i]) ans.push_back(a[i]);
    }
    sort(ans.begin(), ans.end());
    int s = 0;
    int in = ans.size() - 1;
    for (int i = 0; i < n; ++i) {
      if (l[i]) {
        s += a[i];
        cout << a[i] << " ";
      } else {
        s += ans[in];
        cout << ans[in] << " ";
        --in;
      }
    }
    cout << "\n";
  }
}
