You are given an array $a$, consisting of $n$ integers.

Each position $i$ ($1 \le i \le n$) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked positions. You are not allowed to remove any values, add the new ones or rearrange the values on the locked positions. You are allowed to leave the values in the same order as they were.

For example, let $a = [-1, 1, \underline{3}, 2, \underline{-2}, 1, -4, \underline{0}]$, the underlined positions are locked. You can obtain the following arrays:   $[-1, 1, \underline{3}, 2, \underline{-2}, 1, -4, \underline{0}]$;  $[-4, -1, \underline{3}, 2, \underline{-2}, 1, 1, \underline{0}]$;  $[1, -1, \underline{3}, 2, \underline{-2}, 1, -4, \underline{0}]$;  $[1, 2, \underline{3}, -1, \underline{-2}, -4, 1, \underline{0}]$;  and some others. 

Let $p$ be a sequence of prefix sums of the array $a$ after the rearrangement. So $p_1 = a_1$, $p_2 = a_1 + a_2$, $p_3 = a_1 + a_2 + a_3$, $\dots$, $p_n = a_1 + a_2 + \dots + a_n$.

Let $k$ be the maximum $j$ ($1 \le j \le n$) such that $p_j < 0$. If there are no $j$ such that $p_j < 0$, then $k = 0$.

Your goal is to rearrange the values in such a way that $k$ is minimum possible.

Output the array $a$ after the rearrangement such that the value $k$ for it is minimum possible. If there are multiple answers then print any of them.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.

Then $t$ testcases follow.

The first line of each testcase contains a single integer $n$ ($1 \le n \le 100$) — the number of elements in the array $a$.

The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^5 \le a_i \le 10^5$) — the initial array $a$.

The third line of each testcase contains $n$ integers $l_1, l_2, \dots, l_n$ ($0 \le l_i \le 1$), where $l_i = 0$ means that the position $i$ is unlocked and $l_i = 1$ means that the position $i$ is locked.


-----Output-----

Print $n$ integers — the array $a$ after the rearrangement. Value $k$ (the maximum $j$ such that $p_j < 0$ (or $0$ if there are no such $j$)) should be minimum possible. For each locked position the printed value should be equal to the initial one. The values on the unlocked positions should be an arrangement of the initial ones.

If there are multiple answers then print any of them.


-----Example-----
Input
5
3
1 3 2
0 0 0
4
2 -3 4 -1
1 1 1 1
7
-8 4 -2 -6 4 7 1
1 0 0 0 1 1 0
5
0 1 -4 6 3
0 0 0 1 1
6
-1 7 10 4 -8 -1
1 0 0 0 0 1

Output
1 2 3
2 -3 4 -1
-8 -6 1 4 4 7 -2
-4 0 1 6 3
-1 4 7 -8 10 -1


-----Note-----

In the first testcase you can rearrange all values however you want but any arrangement will result in $k = 0$. For example, for an arrangement $[1, 2, 3]$, $p=[1, 3, 6]$, so there are no $j$ such that $p_j < 0$. Thus, $k = 0$.

In the second testcase you are not allowed to rearrange any elements. Thus, the printed array should be exactly the same as the initial one.

In the third testcase the prefix sums for the printed array are $p = [-8, -14, -13, -9, -5, 2, 0]$. The maximum $j$ is $5$, thus $k = 5$. There are no arrangements such that $k < 5$.

In the fourth testcase $p = [-4, -4, -3, 3, 6]$.

In the fifth testcase $p = [-1, 3, 10, 2, 12, 11]$.

Starter code:

Solutions:
import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
import sys
letters = ascii_letters
input = stdin.readline
#print = stdout.write

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    can = list(map(int, input().split()))
    vals = sorted([i for i in range(n) if not can[i]], key=lambda x: -arr[x])
    res = [0] * n
    last = 0
    for i in range(n):
        if can[i]:
            res[i] = arr[i]
        else:
            res[i] = arr[vals[last]]
            last += 1
    print(*res)


import sys
import math as mt
import collections as cc
import sys
import itertools as it
input=sys.stdin.readline
I=lambda:list(map(int,input().split()))
for tc in range(int(input())):
	n,=I()
	ar=I()
	l=I()
	s=[]
	ll=l.copy()
	loc=cc.defaultdict(int)
	for i in range(n):
		if l[i]==0:
			s.append(ar[i])
			loc[i]=-10**6	
		else:
			loc[i]=ar[i]
	s.sort(reverse=True)
	j=0
	for i in range(n):
		if l[i]==0:
			l[i]=s[j]
			j+=1
		else:
			l[i]=ar[i]
	print(*l)



from collections import deque

t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    l = list(map(int, input().split()))
    
    bckt = []
    for i in range(n):
        if not l[i]:
            bckt.append(a[i])
            a[i] = 10**9
            
    bckt.sort(reverse=True)
    bckt = deque(bckt)
    
    for i in range(n):
        if a[i] == 10**9:
            a[i] = bckt.popleft()
            
    print(*a)

t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    l = list(map(int, input().split()))

    s = []
    out = [10**6] * n
    for i in range(n):
        if l[i]:
            out[i] = a[i]
        else:
            s.append(a[i])
    s.sort()
    for i in range(n):
        if out[i] == 10**6:
            out[i] = s.pop()
    print(' '.join(map(str,out)))


for _ in range (int(input())):
    n = int(input())
    a =  [int(i) for i in input().split()]
    l =  [int(i) for i in input().split()]
    b = []
    for i in range (n):
        if l[i]==0:
            b.append(a[i])
    b.sort(reverse=True)
    ind = 0
    for i in range (n):
        if l[i]==0:
            a[i]=b[ind]
            ind+=1
    print(*a)

from sys import stdin
def input(): return stdin.readline().rstrip()

for _ in range(int(input())):
    L = int(input())
    lockSort = []
    s = list(map(int, input().split()))
    l = list(map(int, input().split()))
    for i, c in enumerate(s):
        if l[i] == 0:
            lockSort.append(c)
    lockSort = sorted(lockSort)[::-1]
    cnt = 0
    for i, c in enumerate(s):
        if l[i] == 1:
            print(c, end=" ")
        else:
            print(lockSort[cnt], end=" ")
            cnt += 1
    print()


for t in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    lock = list(map(int, input().split()))
    b = []
    for i in range(n):
        if lock[i] == 0:
            b.append(a[i])
    b.sort()
    b=b[::-1]
    ind = 0
    for i in range(n):
        if lock[i] == 0:
            a[i]=b[ind]
            ind+=1
    a=[str(i) for i in a]
    print(" ".join(a))


INF = float('inf')


def prod(arr):
    ret = 1
    for x in arr:
        ret *= x

    return ret


def tc():
    n = int(input())
    a = list(map(int, input().split()))
    l = list(map(int, input().split()))

    uis = []
    for i in range(n):
        if not l[i]:
            uis.append(i)

    uvals = [a[i] for i in uis]
    uvals.sort()

    for i in uis:
        a[i] = uvals.pop()

    print(' '.join(map(str, a)))


################
T = int(input())
for _ in range(T):
    tc()


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    l = list(map(int, input().split()))
    b = []
    for i in range(n):
        if l[i] == 0:
            b.append(a[i])
    b.sort()
    b.reverse()
    j = 0
    for i in range(n):
        if l[i] == 0:
            a[i] = b[j]
            j += 1
    print(*a)

input=__import__('sys').stdin.readline
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    blocked=[]
    binds=[]
    b=list(map(int,input().split()))
    for i in range(n):
        if not b[i]:blocked+=a[i],;binds+=i,
    blocked.sort()
    for i in range(len(binds)):
        a[binds[i]]=blocked[i]
    k1=-1
    cs=0
    for i in range(n):
        cs+=a[i]
        if cs<0:k1=i
    ans1=a.copy()
    blocked.reverse()
    for i in range(len(binds)):
        a[binds[i]]=blocked[i]
    k2=-1
    cs=0
    for i in range(n):
        cs+=a[i]
        if cs<0:k2=i
    ans2=a.copy()
    ans=ans1 if k1<k2 else ans2
    print(*ans)

import sys
input = sys.stdin.readline

t=int(input())
for tests in range(t):
    n=int(input())
    A=list(map(int,input().split()))
    l=list(map(int,input().split()))

    B=[]
    for i in range(n):
        if l[i]==0:
            B.append(A[i])
    B.sort(reverse=True)

    ind=0
    for i in range(n):
        if l[i]==0:
            A[i]=B[ind]
            ind+=1

    print(*A)
            

    
    
    


t = int(input())
for i in range(t):
    n = int(input())
    nums = list(map(int, input().split()))
    st = list(map(int, input().split()))
    sv = []
    for j in range(n):
        if st[j] == 0:
            sv.append(nums[j])
    sv.sort(reverse=True)
    new = []
    k = 0
    for j in range(n):
        if st[j] == 1:
            new.append(nums[j])
        else:
            new.append(sv[k])
            k += 1
    print(*new)

t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    l = list(map(int,input().split()))
    b = []
    if sum(l) < n: # exist non-blocked
        for i in range(n):
            if l[i] == 0:
                b.append(a[i])
        b.sort(reverse=True)
        j = 0
        for i in range(n):
            if l[i] == 0:
                print(b[j], end =' ')
                j += 1
            else:
                print(a[i], end =' ')
        print()
    else:
        for i in range(n):
            print(a[i],end=' ')
        print()

import sys,os,io
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
T = int(input())
ans = [0]*T
for t in range(T):
  N = int(input())
  A = list(map(int, input().split()))
  L = list(map(int, input().split()))
  B = [A[i] for i in range(N) if L[i]==0]
  B.sort()
  ans[t] = []
  for i in range(N):
    if L[i]==0:
      ans[t].append(B.pop())
    else:
      ans[t].append(A[i])
for a in ans:
  print(*a)

for _ in range(int(input())):
    n = int(input())
    *arr, = list(map(int, input().split()))
    *locks, = list(map(int, input().split()))

    locked = []
    unlocked = []
    for v, is_locked in zip(arr, locks):
        if not is_locked:
            unlocked.append(v)
    unlocked.sort(reverse=True)
    arr_idx = 0
    unlocked_idx = 0
    while unlocked_idx < len(unlocked) and arr_idx < len(arr):
        if not locks[arr_idx]:
            arr[arr_idx] = unlocked[unlocked_idx]
            unlocked_idx += 1
        arr_idx += 1
    print(*arr)


from math import inf, ceil
from heapq import *
from collections import defaultdict

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    brr = list(map(int, input().split()))
    crr = [arr[i] for i in range(n) if not brr[i]]
    crr.sort(reverse=True)
    ind = 0
    for i in range(n):
        if not brr[i]:
            arr[i] = crr[ind]
            ind += 1
    print(*arr)

def main():
    n = int(input())
    a = list(map(int,input().split()))
    l = list(map(int,input().split()))
    new_lst = []
    for i in range(n):
        if not l[i]:
            new_lst.append(a[i])
    new_lst = sorted(new_lst, reverse=True)
    k = 0
    for i in range(n):
        if not l[i]:
            a[i] = new_lst[k]
            k += 1
    sm = 0
    for i in a:
        print(i, end=" ")
    print()

def __starting_point():
    t = int(input())
    for i in range(t):
        main()

__starting_point()

for _ in range(int(input())):
    N = int(input())
    List = [int(x) for x in input().split()]
    Lock = [int(x) for x in input().split()]
    X = []
    for i in range(N):
        if(not Lock[i]):
            X.append(List[i])
    X.sort(reverse  = True)
    j = 0
    for i in range(N):
        if(not Lock[i]):
            List[i] = X[j]
            j+=1
    print(*List)

t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split(" ")))
    b = list(map(int, input().split(" ")))
    c=[]
    for i in range(n):
        if b[i]==0:
            c.append(a[i])
    c.sort(reverse=True)
    k=0
    for i in range(n):
        if b[i]==0:
            a[i]=c[k]
            k+=1
    print(" ".join(str(j) for j in a))


import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

# available on Google, not available on Codeforces
# import numpy as np
# import scipy


def solve(arr, brr):  # fix inputs here
    console("----- solving ------")

    movable = []
    for a,b in zip(arr,brr):
        if b == 0:
            movable.append(a)
    
    movable = sorted(movable)
    # console(movable)

    for i in range(len(arr)):
        if brr[i] == 0:
            arr[i] = movable.pop()

    # return a string (i.e. not a list or matrix)
    return arr 


def console(*args):  # the judge will not read these print statement
    print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return

# fast read all
# sys.stdin.readlines()

for case_num in range(int(input())):
    # read line as a string
    # strr = input()

    # read line as an integer
    k = int(input())
    
    # read one line and parse each word as a string
    # lst = input().split()

    # read one line and parse each word as an integer
    arr = list(map(int,input().split()))
    brr = list(map(int,input().split()))

    # read matrix and parse as integers (after reading read nrows)
    # lst = list(map(int,input().split()))
    # nrows = lst[0]  # index containing information, please change
    # grid = []
    # for _ in range(nrows):
    #     grid.append(list(map(int,input().split())))

    res = solve(arr,brr)  # please change
    
    # Google - case number required
    # print("Case #{}: {}".format(case_num+1, res))

    # Codeforces - no case number required
    print(" ".join([str(x) for x in res]))


import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))

t,=I()
for i in range(t):
	n,=I()
	a=I()
	l=I()
	ar=[a[i] for i in range(n) if l[i]==0]
	ar.sort(reverse=True)
	x=0
	for i in range(n):
		if l[i]==0:
			a[i]=ar[x]
			x+=1
	print(*a)


from sys import stdin
def input(): return stdin.readline()
def lmi(): return list(map(int, input().split()))

T = int(input())
for _ in range(T):
    input()
    temp = list()
    s, l = lmi(), lmi()
    for i, c in enumerate(s):
        if l[i] == 0: temp.append(c)
    temp = sorted(temp)[::-1]
    cc = 0
    for i, x in enumerate(s):
        if l[i] == 1: print(x, end=" ")
        else:
            print(temp[cc], end=" ")
            cc += 1
    print()