#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  int n;
  cin >> t;
  while (t--) {
    cin >> n;
    int a[n];
    vector<int> elements, pelements;
    int isnegative = 0, isunlocked = 0, isnegunlocked = 0;
    int locked[n];
    long long int res[n], prefix[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] < 0) isnegative = 1;
    }
    for (int i = 0; i < n; i++) {
      cin >> locked[i];
      if (locked[i] == 0) isunlocked = 1;
      if (locked[i] == 0 && a[i] < 0) isnegunlocked = 1;
      if (locked[i] == 1) {
        res[i] = a[i];
      } else {
        res[i] = INT_MIN;
        elements.push_back(a[i]);
      }
    }
    int k = 0;
    int p = 0;
    sort(elements.begin(), elements.end(), greater<int>());
    for (int i = 0; i < n; i++) {
      if (locked[i] == 1) {
      } else {
        a[i] = elements[k];
        k++;
      }
    }
    for (int i = 0; i < n; i++) cout << a[i] << " ";
    cout << endl;
  }
}
