for ix in range(int(input())):
    n=int(input())
    a=list(map(int, input().split()))
    sig=a[0]>0
    b=[[a[0]]]
    for i in range(1,n):
        if (a[i]>0)==sig:
            b[-1].append(a[i])
        else:
            b.append([a[i]])
            sig=not sig
    sum=0
    for i in b:
        sum+=max(i)
    print(sum)