#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n], b[n], pos = 0, neg = 0, a1 = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] > 0)
        pos++;
      else
        neg++;
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
      if (b[i] == 1) a1++;
    }
    for (int i = 0; i < n; i++) {
      if (a1 == n || neg == 0)
        break;
      else if (b[i] != 1) {
        for (int j = i + 1; j < n; j++) {
          if (b[j] == 1)
            continue;
          else if (b[j] != 1) {
            if (a[i] < a[j]) swap(a[i], a[j]);
          }
        }
      }
    }
    for (int i = 0; i < n; i++) cout << a[i] << " ";
    cout << endl;
  }
  return 0;
}
