for _ in range(int(input())):
    n= int(input())
    a= list(map(int,input().split()))
    l=[[] for i in range(n)]
    l[0].append(a[0])
    j=0
    for i in range(1,n):
        if (l[j][-1]>0 and a[i]<0) or (l[j][-1]<0 and a[i]>0):
            j+=1
        l[j].append(a[i])
    
    for i in range(len(l)):
        if len(l[i])==0:
            l = l[:i]
            break
    s=0
    for i in range(len(l)):
        s+= max(l[i])
    print(s)
        
        
