#include <bits/stdc++.h>
using namespace std;
int t, n;
int a[105];
int l[105];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    vector<int> v;
    for (int i = 0; i < n; i++) {
      cin >> l[i];
      if (!l[i]) v.push_back(a[i]);
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    int y = 0;
    for (int i = 0; i < n; i++) {
      if (!l[i]) {
        cout << v[y] << " ";
        y++;
      } else {
        cout << a[i] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}
