ins = int(input())

entries = []
lens = []

for i in range (0, ins):
    length = int(input())
    instr = input()
    instr = instr.split(' ')
    entries.append(instr)
    lens.append(length)

for i in range (0, ins):
    curr = entries[i]
    sign = ''

    sum = 0

    if (int(curr[0])<0):
        sign = 'neg'
    else:
        sign = 'pos'
    
    last = int(curr[0])
    alt_list = [last]
    for j in range (1, len(curr)):
        temp = int(curr[j])
        
        if (temp<0):
            tsign = 'neg'
        else:
            tsign = 'pos'

        if (sign==tsign and temp>alt_list[-1]):
            alt_list[-1] = temp
        
        if (sign!=tsign):
            sign = tsign
            sum = sum + alt_list[-1]
            alt_list.append(temp)
    sum = sum + alt_list[-1]

    
    print (sum)