t = int(input())
for _ in range(t):
    l = int(input())
    data = list(map(int,input().split()))
    s=[]
    i =0 
    while i<l:
        if data[i]>0:
            for j in range(i,l):
                if data[j]<0:
                    break
                elif j==l-1 and data[j]>0:
                    j=j+1
                    break
            s.append(max(data[i:j]))
            i=j
        elif data[i]<0:
            for j in range(i,l):
                if data[j]>0:
                    break
                elif j==l-1 and data[j]<0:
                    j=j+1
                    break
            s.append(max(data[i:j]))
            i=j
    print(sum(s))
        