#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
  int t, n, cnt = 0;
  int a[105], b[105], c[105];
  cin >> t;
  while (t--) {
    cin >> n;
    cnt = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &b[i]);
      if (b[i] == 0) c[++cnt] = a[i];
    }
    sort(c + 1, c + cnt + 1, cmp);
    cnt = 0;
    for (int i = 1; i <= n; i++) {
      if (b[i])
        cout << a[i] << ' ';
      else
        cout << c[++cnt] << ' ';
    }
    cout << endl;
  }
}
