#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tt;
  cin >> tt;
  while (tt--) {
    long long a, b, c, d, e, f, i, j, k, m, n, o, x, y;
    cin >> n;
    long long ar[n + 1], ab[n + 1];
    for (i = 1; i <= n; i++) cin >> ar[i];
    vector<int> v;
    for (i = 1; i <= n; i++) {
      cin >> a;
      ab[i] = a;
      if (a == 0) v.push_back(ar[i]);
    }
    sort(v.rbegin(), v.rend());
    long long start = 0;
    for (i = 1; i <= n; i++) {
      if (ab[i] == 0) ar[i] = v[start++];
    }
    long long sum = 0, ans = 0;
    for (i = 1; i <= n; i++) {
      sum += ar[i];
      if (ar[i] < 0) ans = i;
    }
    for (i = 1; i <= n; i++) cout << ar[i] << " ";
    cout << "\n";
  }
}
