for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    b=[]
    c=[]
    if a[0]<0:
        pe=-1
    else:
        pe=1
    b.append(a[0])
    for i in range(1,n):
        if pe==1:
            if a[i]>0:
                b.append(a[i])
            else:
                c.append(max(b))
                b=[]
                pe=-1
                b.append(a[i])
        else:
            if a[i]<0:
                b.append(a[i])
            else:
                c.append(max(b))
                b=[]
                pe=1
                b.append(a[i])
    c.append(max(b))
    print(sum(c))



