def sign(x):
    if x>=1:
        return True
    else:
        return False

for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    i=0
    l=[]
    maxx=a[0]
    while i<len(a)-1:
        if sign(a[i])==sign(a[i+1]):
            maxx=max(a[i+1],a[i])
        else:
            l.append(maxx)
            maxx=a[i+1]
        i+=1
    l.append(maxx)
    print(sum(l))