for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    p=0
    m=0
    b=[]
    c=[]
    s=0
    for i in range(len(a)):
        if a[i]>0:
            if len(c)>0:
                s+=max(c)
                c=[]
            b.append(a[i])
        else:
            if len(b)>0:
                s+=max(b)
                b=[]
            c.append(a[i])
    if len(b)>0:
        s+=max(b)
    if len(c)>0:
        s+=max(c)
    print(s)

