#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5;
int a[N], b[N];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
      cin >> b[i];
      if (b[i] == 0) v.push_back(a[i]);
    }
    sort(v.begin(), v.end());
    int cnt = v.size();
    for (int i = 1; i <= n; i++) {
      if (b[i] == 0) a[i] = v[--cnt];
      cout << a[i] << " ";
    }
    cout << endl;
  }
}
