#include <bits/stdc++.h>
using namespace std;
vector<int> pos;
vector<int> neg;
vector<int> zer;
int num[101];
int n, m, k, x, y, t, a[101], l[101], ans[101];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    m = 0;
    memset(ans, 0, sizeof(ans));
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &l[i]);
    for (int i = 1; i <= n; i++) {
      if (l[i]) continue;
      num[++m] = a[i];
    }
    for (int i = 1; i < m; i++)
      for (int j = i + 1; j <= m; j++)
        if (num[i] > num[j]) swap(num[i], num[j]);
    for (int i = 1; i <= n; i++) {
      if (l[i]) {
        ans[i] = a[i];
        continue;
      }
      if (m) {
        ans[i] = num[m--];
      }
    }
    for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
    printf("\n");
  }
  return 0;
}
