#include <bits/stdc++.h>
using namespace std;
long long a, b[10001], c[10001], ans, d[10001], uu;
long long T;
bool cmp(long long q, long long w) { return q > w; }
int main() {
  scanf("%lld", &T);
  for (int ii = 1; ii <= T; ii++) {
    uu = 0;
    scanf("%lld", &a);
    for (int i = 1; i <= a; i++) {
      scanf("%lld", &b[i]);
    }
    long long rr = 0;
    for (int i = 1; i <= a; i++) {
      scanf("%lld", &c[i]);
      if (c[i] == 0) {
        uu++;
        d[uu] = b[i];
      }
    }
    sort(d + 1, d + uu + 1, cmp);
    long long oo = 0;
    for (int i = 1; i <= a; i++) {
      if (c[i] == 1) {
        cout << b[i] << " ";
      } else {
        oo++;
        cout << d[oo] << " ";
      }
    }
    cout << "\n";
  }
  return 0;
}
