number = int(input())

for k in range(number):
    length = int(input())
    text_sequence=input()
    sequence = text_sequence.split()
    for i in range(len(sequence)):
        sequence[i]=int(sequence[i])
    #print(sequence)
    #for l in range(length):
      #  new = int(input())
       # sequence.append(new)



    subsequence_length = 1
    toggle=0
    toggled=0
    total=0
    currentmax=0

    if sequence[0]>0:
        toggle = 1
    else:
        toggle = -1
    #print('Set initial toggle to',toggle)

    #print('Testing sequence',sequence)

    for i in range(len(sequence)):
        if sequence[i]>0 and toggle==-1:
            #print('Toggled!',sequence[i],'is positive')
            subsequence_length += 1
            toggle = 1
            toggled = 1
        elif sequence[i]<0 and toggle==1:
            #print('Toggled!', sequence[i], 'is negative')
            subsequence_length += 1
            toggle = -1
            toggled = 1
        if toggled==1:
            total = total+currentmax
            #print('New total is', total)
            currentmax=0
            toggled = 0
            currentmax=sequence[i]
        if i==len(sequence)-1:
            total = total+currentmax
        else:
            if sequence[i]>currentmax or currentmax==0:
                currentmax = sequence[i]



    #(subsequence_length)
    print(total)
