#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long mod = 1000000007;
    int n, c = 0;
    cin >> n;
    int arr[n + 2], brr[n + 2], sum[n + 2];
    vector<int> a, b;
    for (int i = 0; i < n; i++) cin >> arr[i];
    for (int i = 0; i < n; i++) cin >> brr[i];
    for (int i = 0; i < n; i++) {
      if (brr[i] == 0 && arr[i] < 0) {
        a.push_back(arr[i]);
      } else if (brr[i] == 0 && arr[i] >= 0) {
        b.push_back(arr[i]);
      }
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (int i = 0; i < n; i++) {
      if (brr[i] == 0) {
        if (b.size() > 0) {
          int k = b[b.size() - 1];
          arr[i] = k;
          b.pop_back();
        } else {
          int k = a[a.size() - 1];
          arr[i] = k;
          a.pop_back();
        }
      }
    }
    for (int i = 0; i < n; i++) cout << arr[i] << " ";
    cout << endl;
  }
}
