a=int(input())
for i in range (a):
    b=int(input())
    l=list(map(int,input().split()))
    cnt=0
    p=[[l[0]]]
    for i in range(1,b):
        if (l[i-1]<0 and l[i]<0) or(l[i-1]>0 and l[i]>0):
            p[cnt].append(l[i])
            
        else:
            cnt+=1
            p.append([l[i]])
    l=0
    for i in p:
        l+=max(i)
    print(l)
            
    
