t=int(input())
for _ in range(t):
    n=int(input())
    ar=list(map(int,input().split()))
    alt=[]
    ct=0
    while(ct<n):
        a=[]
        while ct<n:
            a.append(ar[ct])
            ct+=1
            if ct!=0 and ct<n and ar[ct]*ar[ct-1]<0:
                break
        alt.append(max(a))
    print(sum(alt))
