#include <bits/stdc++.h>
using namespace std;
long long t, n, v[105], l[105];
vector<int> tmp;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  while (t--) {
    tmp.clear();
    cin >> n;
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int i = 0; i < n; i++) cin >> l[i];
    for (int i = 0; i < n; i++) {
      if (l[i] == 0) tmp.push_back(v[i]);
    }
    sort(tmp.rbegin(), tmp.rend());
    int ind = 0;
    for (int i = 0; i < n; i++) {
      if (l[i] == 0) {
        v[i] = tmp[ind];
        ind++;
      }
    }
    for (int i = 0; i < n; i++) {
      cout << v[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
