#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 6;
const int mod = pow(10, 9) + 7;
int a[N];
int l[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T;
  cin >> T;
  int n;
  while (T--) {
    cin >> n;
    int x;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> l[i];
    }
    vector<int> v;
    for (int i = 0; i < n; i++) {
      if (l[i] == 0) v.push_back(a[i]);
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    int j = 0;
    for (int i = 0; i < n; i++) {
      if (l[i] == 1) {
        cout << a[i] << " ";
      } else {
        cout << v[j] << " ";
        j++;
      }
    }
    cout << endl;
  }
}
