
t=int(input())
for i in range(t):
    n=int(input())
    x=list(map(int,input().split()))
    max=x[0]
    sum=0
    maxsign=x[0]/abs(x[0])
    for j in range(n):
        if(maxsign==x[j]/abs(x[j])):
            if(max<x[j]):
                max=x[j]
        else:
            maxsign=x[j]/abs(x[j])
            sum+=max
            max=x[j]
    sum+=max
    print(sum)
            