#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, i, l1 = 0, l2 = 0, j, x;
    cin >> n;
    vector<int> a;
    vector<int> v;
    vector<int> s;
    for (i = 0; i < n; i++) {
      cin >> x;
      a.push_back(x);
    }
    for (i = 0; i < n; i++) {
      cin >> x;
      v.push_back(x);
    }
    for (i = 0; i < n; i++) {
      if (v[i] == 0) {
        s.push_back(a[i]);
      }
    }
    sort(s.begin(), s.end());
    vector<int> p;
    vector<int> q;
    j = 0;
    long long int sum = 0;
    for (i = 0; i < n; i++) {
      if (v[i] == 0) {
        sum = sum + s[j];
        p.push_back(s[j]);
        j++;
      } else {
        p.push_back(a[i]);
        sum = sum + a[i];
      }
      if (sum < 0) {
        l1 = i + 1;
      }
    }
    sort(s.begin(), s.end(), greater<int>());
    sum = 0;
    j = 0;
    for (i = 0; i < n; i++) {
      if (v[i] == 0) {
        sum = sum + s[j];
        q.push_back(s[j]);
        j++;
      } else {
        sum = sum + a[i];
        q.push_back(a[i]);
      }
      if (sum < 0) {
        l2 = i + 1;
      }
    }
    if (l1 < l2) {
      for (i = 0; i < n; i++) {
        cout << p[i] << " ";
      }
      cout << "\n";
    } else {
      for (i = 0; i < n; i++) {
        cout << q[i] << " ";
      }
      cout << "\n";
    }
  }
  return 0;
}
