def sig(a):
    if a <  0 :
        return -1
    else:
        return 1
def fun(n):
    a=[]
    l=[]
    a.append(n[0])
    for i in range(1,len(n)):
        if( sig(n[i-1]) == sig(n[i]) ):
            a.append(n[i])
        
        else:
            l.append(a)
            a=[]
            a.append(n[i])
    
    if a is not []:
        l.append(a)
    s=0
    for i in l:
        s+= max(i)
        
    return s
        

T = int(input())
for _ in range( T):
    y= input()
    n = [int(x) for x in input().split()]
    
    x= fun(n)
    print(x)
