#include <bits/stdc++.h>
using namespace std;
vector<int> fix, notfix;
int o[200], u[200];
int main(void) {
  int q;
  scanf("%d", &q);
  while (q--) {
    fix.clear();
    notfix.clear();
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%d", &o[i]);
    }
    for (int i = 0; i < n; i++) {
      scanf("%d", &u[i]);
    }
    for (int i = 0; i < n; i++) {
      if (u[i])
        fix.push_back(o[i]);
      else
        notfix.push_back(o[i]);
    }
    sort(notfix.begin(), notfix.end(), [](int& a, int& b) { return a > b; });
    int i = 0, j = 0;
    for (int k = 0; k < n; k++) {
      if (u[k])
        printf("%d ", fix[i++]);
      else
        printf("%d ", notfix[j++]);
    }
    puts("");
  }
}
