#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, t, i, s = 0, e = 0, f = 0, j = 0;
  cin >> t;
  while (t--) {
    cin >> a;
    vector<int> v;
    int b[a], c[a];
    for (i = 0; i < a; i++) {
      cin >> b[i];
      s = s + b[i];
      if (b[i] < 0) {
        e++;
      }
    }
    for (i = 0; i < a; i++) {
      cin >> c[i];
      if (c[i] == 0) {
        f++;
      }
    }
    if (s < 0 || e == 0 || f == 0) {
      for (i = 0; i < a; i++) {
        cout << b[i] << " ";
      }
    } else {
      for (i = 0; i < a; i++) {
        if (c[i] == 0) {
          v.push_back(b[i]);
        }
      }
      sort(v.begin(), v.end(), greater<int>());
      for (i = 0; i < a; i++) {
        if (c[i] == 1) {
          cout << b[i] << " ";
        } else {
          cout << v[j] << " ";
          j++;
        }
      }
    }
    cout << endl;
    e = 0;
    f = 0;
    j = 0;
    s = 0;
  }
}
