T = int(input())
out = []
for i in range(T):
    n = int(input())
    l = list(map(int,input().split()))
    out1 = []
    out1.append([l[0]])
    count = 0
    
    for j in range(1,n):
        if(l[j]*l[j-1]<0):
            count = count+1
            out1.append([l[j]])
        else:
            out1[count].append(l[j])
    out2 = []
    
    for j in range(len(out1)):
        if(out1[j][0]<0):
            out2.append(max(out1[j]))
            
        else:
            out2.append(max(out1[j]))
    out.append(sum(out2))
for i in range(T):
    print(out[i])
        

            