t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    x=0
    s=[]
    for i in range(n):
        if i==0:
            x=a[i]
        elif i==n-1 :
            if x>0:
                if a[i]<0 :
                    s.append(x)
                    s.append(a[i])
                elif a[i]>0 :
                    if a[i]>x :
                        s.append(a[i])
                    else :
                        s.append(x)
            if x<0:
                if a[i]>0 :
                    s.append(x)
                    s.append(a[i])
                elif a[i]<0 :
                    if a[i]>x :
                        s.append(a[i])
                    else :
                        s.append(x)
        else :
            if x>0 :
                if a[i]<0 :
                    s.append(x)
                    x=a[i]
                elif a[i]>0:
                    if a[i]>x:
                        x=a[i]
            elif x<0 :
                if a[i]>0:
                    s.append(x)
                    x=a[i]
                elif a[i]<0:
                    if a[i]>x:
                        x=a[i]
    print(sum(s))