##jis point pe negative aane lagega waha pe mereko stop karna hai
t=int(input())
for _ in range(t):
    n=int(input())
    a=[int(x) for x in input().split()]
    b=[]
    p=[]
    np=[]
    s=0
    for i in range(len(a)):
        if a[i]<0:
            if p!=[]:
                #b.append(p)
                s+=max(p)
                p=[]
            np.append(a[i])
        elif a[i]>0:
            if np!=[]:
                #b.append(np)
                s+=max(np)
                np=[]
            p.append(a[i])
    if np!=[]:
        s+=max(np)
    else:
        s+=max(p)
    print(s)
            
            
        
