#include <bits/stdc++.h>
using namespace std;
long long int M = 1000000007;
void solve() {
  vector<long long int> pos, neg;
  long long int i, n;
  cin >> n;
  vector<long long int> a(n), x(n);
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) {
    cin >> x[i];
    if (x[i] == 0) {
      if (a[i] < 0)
        neg.push_back(a[i]);
      else
        pos.push_back(a[i]);
    }
  }
  vector<long long int> final;
  sort((neg).begin(), (neg).end(), greater<long long int>());
  sort((pos).begin(), (pos).end(), greater<long long int>());
  long long int j = 0, k = 0, sum = 0;
  for (i = 0; i < n; i++) {
    if (x[i] == 1) {
      cout << a[i] << " ";
      continue;
    }
    if (k < pos.size()) {
      cout << pos[k++] << " ";
    } else {
      cout << neg[j++] << " ";
    }
  }
  cout << endl;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
