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)


    if len(sequence)==1:
        print(sequence[0])
    else:
        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 sequence[i]>currentmax or currentmax==0 or total==0:
                    currentmax = sequence[i]
                    #print('New block max is',currentmax)
            if i==len(sequence)-1:
                total = total+currentmax



        #(subsequence_length)
        print(total)
