t=int(input())

while t!=0:
    t=t-1
    j=int(input())
    numbers = input()
    list = numbers.split(" ")
    final=0
    m=len(list)
    ndigit=0


    digit=0
    for i in range(1,m-1):

        currentnumber=int(list[i])
        nextnumber=int(list[i+1])
        if nextnumber*currentnumber>0:
            if nextnumber>=currentnumber:
                digit=nextnumber
            else:
                digit=currentnumber

        if nextnumber*currentnumber<= 0:
            final+=digit
            digit=0

    for i in range(0,m):
        lastnumber=int(list[m-1-i])
        secondnumber=int(list[m-2-i])
        if lastnumber*secondnumber>0:
            if lastnumber>secondnumber:
                ndigit=lastnumber
            else:
                ndigit=secondnumber
        if lastnumber*secondnumber<0:
            break
    final=final+ndigit

    print(final)





