t=int(input())
def maxsum(l):
    positive=[]
    negative=[]
    s=0
    if l[0]>0:
        positive.append(l[0])
        if l[1]<0:
            s+=l[0]
            positive=[]
    else:
        negative.append(l[0])
        if l[1]>0:
            s+=l[0]
            negative=[]
    for i in range(1,len(l)-1):
        if l[i]>0:
            positive.append(l[i])
            if l[i+1]<0:
                s+=max(positive)
                positive=[]
        else:
            negative.append(l[i])
            if l[i+1]>0:
                s+=max(negative)
                negative=[]
    if l[-1]>0:
        positive.append(l[-1])
        if l[-2]<0:
            s+=l[-1]
        else:
            s+=max(positive)
    else:
        negative.append(l[-1])
        if l[-2]>0:
            s+=l[-1]
        else:
            s+=max(negative)
for i in range (t):
    n=int(input())
    List=list(map(int,input().split()))
    print(maxsum(List))