import collections
t=int(input())
for _ in range(t):
    n=int(input())
    l=list(map(int, input().split()))
    l1=[]
    l1.append(l[0])
    for i in range(1,len(l)):
        if l[i]<0:
            if l1[-1]<0:
                if l[i]>l1[-1]:
                    l1[-1]=l[i]
            else:
                l1.append(l[i])
        else:
            if l1[-1]>0:
                if l[i]>l1[-1]:
                    l1[-1]=l[i]
            else:
                l1.append(l[i])
    print(sum(l1))
