#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc = 1;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    vector<pair<int, int> > arr;
    vector<int> b;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      arr.push_back({x, 1});
    }
    for (size_t j = 0; j < n; j++) {
      int x;
      cin >> x;
      if (x == 0) b.push_back(arr[j].first);
      arr[j].second = x;
    }
    sort(b.begin(), b.end(), [](const int A, const int B) { return A > B; });
    int itr = 0;
    for (size_t i = 0; i < n; i++) {
      if (arr[i].second == 0)
        cout << b[itr++] << " ";
      else
        cout << arr[i].first << " ";
    }
    cout << endl;
  }
  return 0;
}
