#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a[1010], b[1010];
    vector<int> vec;
    int n;
    cin >> n;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      sum += a[i];
    }
    for (int i = 1; i <= n; i++) {
      cin >> b[i];
      if (b[i] == 0) vec.push_back(a[i]);
    }
    if (sum >= 0)
      sort(vec.begin(), vec.end(), cmp);
    else
      sort(vec.begin(), vec.end());
    int temp = 0;
    for (int i = 1; i <= n; i++) {
      if (b[i] == 0) {
        a[i] = vec[temp];
        temp++;
      } else
        continue;
    }
    for (int i = 1; i <= n; i++) {
      cout << a[i];
      if (i != n) cout << ' ';
    }
    cout << '\n';
  }
  return 0;
}
