t= int(input())
def f(n,l):
    a=l[0]
    sum=0
    for i in l:
        if (a//i<0):
            sum+=a
            a=i
        elif a<i:
            a=i
        else:
            continue
    print(sum+a)
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    f(n,l)
        