for i in range(int(input())):
    n=int(input())
    x=[int(q) for q in input().split()]
    s=0
    e=0
    for i in range(n):
        if x[i]>0:
            s+=1
        if x[i]<0:
            e+=1
    if s==n or e==n:
        print(max(x))
    else:
        l=0
        ans=0
        a=x[0]
        if x[0]>0:
            l=1
        if x[0]<0:
            l=-1
        for i in range(1,n):
            if l==-1 and x[i]<0:
                a=max(x[i],a)
                continue
            if l==1 and x[i]>0:
                a=max(x[i],a)
                continue
            ans+=a
            a=x[i]
            if x[i]>0:
                l=1
            if x[i]<0:
                l=-1
        print(ans+a)