import math
t=input()
t=int(t)
while(t):
    t-=1
    n=input()
    n=int(n)
    arr=list(map(int,input().split()))
    s=0
    pos=arr[0]
    if pos>0:
        want='+'
    else:
        want='-'
    
    for i in range(n):
        if arr[i]>0:
            sign='+'
        else:
            sign='-'

        if want=='+' and sign=='+':
                if arr[i]>pos:
                    pos=arr[i]
        elif want=='+' and sign=='-':
            #print(i,pos)
            s=s+pos
            pos=arr[i]
            want='-'
        elif want=='-' and sign=='-':
            if arr[i]>pos:
                pos=arr[i]
        else:
            #print(i,pos)
            s=s+pos
            pos=arr[i]
            want='+'
    s=s+pos
    print(s)
 
