import itertools

t = int(input())
cnt = 0
for cnt in range(t):
    n = int(input())
    a = list()
    pos_cnt = 0
    neg_cnt = 0
    counter = 0
    a=list(map(int,input().split()))
    pos = list()
    neg = list()
    final = 0
    max_pos = 0
    min_neg = 0
    
    if(a[0] > 0):
        counter = 1
        max_pos = a[0]
    else:
        counter = -1
        min_neg = a[0]
    for i in a:
        if(i > 0):
            #print("Hello")
            if(counter == 1):
                #print("YES")
                if(max_pos <= i):
                    max_pos = i
            else:
               # print("NO")
                #print(max_pos)
                final += min_neg
                counter = 1
                max_pos = i
        else:
            #print("Hi")
            if(counter == -1):
                #print("y")
                if(min_neg <= i):
                    min_neg = i
            else:
                #print("n")
                #print(min_neg)
                final += max_pos
                counter = -1
                min_neg = i
                
    if(counter == 1):
        final += max_pos
    else:
        final += min_neg
    
    '''if(a[0] > 0):
        counter = 1
        pos_cnt += 1
    else:
        counter = -1
        neg_cnt += 1
    for i in a:
        if(i < 0):
            neg.append(i)
            if(counter == 1):
                pos.append(0)
                neg_cnt += 1
                counter = -1
        else:
            pos.append(i)
            if(counter == -1):
                neg.append(0)
                pos_cnt += 1
                counter = 1
    
    if(neg_cnt > pos_cnt):
        
    print(pos)
    print(neg)
    print(pos_cnt)
    print(neg_cnt)'''
    print(final)
    pos.clear()
    neg.clear()
                
    