# cook your dish here
test = int(input())
while(test):
    
    n = int(input())
    s = input()
    s = s.split(' ')
    # pos = []
    neg = []
    temp = []
    state = True;
    start = True;
    index = 0
    for i in s:
        i = int(i)
        # print(i)
        if start:
            if i<0:
                temp.append(i)
                state = False
            else:
                temp.append(i)
                state = True
            start = False
        elif index == len(s)-1:
            if (i>0 and state==True) or (i<0 and state==False):
                temp.append(i)
                temp.sort()
                temp = temp[::-1]
                neg.append(temp[0])
                temp = []
            else:
                temp.sort()
                temp = temp[::-1]
                neg.append(temp[0])
                neg.append(i)
                temp = []
        elif i>0 and state==True:
            temp.append(i)
            state = True
        elif i<0 and state==False:
            temp.append(i)
            state = False
        elif i>0 and state==False:
            temp.sort()
            temp = temp[::-1]
            neg.append(temp[0])
            temp = []
            temp.append(i)
            state = True
        elif i<0 and state==True:
            temp.sort()
            temp = temp[::-1]
            neg.append(temp[0])
            temp = []
            temp.append(i)
            state = False
        index+=1
    su  = 0
    # print(neg)
    for i in neg:
        su += i
    # print(su)
    print(neg)
    test-=1