#include <bits/stdc++.h>
using namespace std;
int t;
int n, a[104], l[104], k[104], am, duong;
vector<int> va, vd;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  int i, j, k;
  while (t != 0) {
    t--;
    cin >> n;
    for (i = 1; i <= n; i++) cin >> a[i];
    for (i = 1; i <= n; i++) cin >> l[i];
    va.clear();
    vd.clear();
    for (i = 1; i <= n; i++)
      if (l[i] == 0 && a[i] > 0)
        vd.push_back(a[i]);
      else if (l[i] == 0)
        va.push_back(a[i]);
    am = va.size();
    duong = vd.size();
    for (i = 0; i < duong; i++) vd[i] = -vd[i];
    for (i = 0; i < am; i++) va[i] = -va[i];
    sort(vd.begin(), vd.end());
    sort(va.begin(), va.end());
    for (i = 0; i < duong; i++) vd[i] = -vd[i];
    for (i = 0; i < am; i++) va[i] = -va[i];
    j = 0;
    k = 0;
    for (i = 1; i <= n; i++)
      if (l[i] == 1)
        cout << a[i] << ' ';
      else {
        if (j < duong) {
          cout << vd[j] << ' ';
          j++;
          continue;
        }
        cout << va[k] << ' ';
        k++;
      }
    cout << '\n';
  }
  return 0;
}
