for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    l1=[]
    temp=l[0]
    for i in range(1,n):
        if(temp>0 and l[i]>0):
            temp=max(temp,l[i])
        elif(temp<0 and l[i]<0):
            temp=max(temp,l[i])
        elif(temp<0 and l[i]>0):
            l1.append(temp)
            temp=l[i]
        elif(temp>0 and l[i]<0):
            l1.append(temp)
            temp=l[i]
    l1.append(temp)
    #print(l1)
    print(sum(l1))