for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    l=[a[0]]
    for i in range(1,n):
        if l[-1]>0 and a[i]>0:
            p=l.pop()
            l.append(max(p,a[i]))
        if l[-1]<0 and a[i]<0:
            p=l.pop()
            l.append(max(p,a[i]))
        if l[-1]>0 and a[i]<0:
            l.append(a[i])
        if l[-1]<0 and a[i]>0:
            l.append(a[i])
    if len(l)==1:
        print(l[0])
    else:
        s=0
        i=0
        if len(l)%2==1:
            p=l.pop()
            s+=p
        while i< len(l):
                s+=l[i]+l[i+1]
                i+=2
        print(s)
            
            