for _ in range(int(input())):
    n=int(input())
    ar=[int(x) for x in input().split()]
    fr=[ar[0]]
    
    p=0
    for i in range(1,n):
        if(ar[i]<0 and fr[p]<0):
            if(ar[i]>fr[p]):
                fr[p]=ar[i]
        elif(ar[i]>0 and fr[p]>0):
            if(ar[i]>fr[p]):
                fr[p]=ar[i]
        else:
            p+=1
            fr.append(ar[i])
    sm=0
    for i in fr:
        sm+=i
    print(sm)
