for _ in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    convert = [0]*n
    for i in range(n):
        if a[i]>0:
            convert[i]=1

    if convert[0]==1:
        one = 1
        i = 0
        ans1 = 0
        maxx1 = a[0]
        while i<n and convert[i]==1:
            maxx1 = max(maxx1,a[i])
            i+=1
            if i<n and convert[i]==0:
                ans1+=maxx1
                one+=1
                minn1 = a[i]
                while i<n and convert[i]==0:
                    minn1 = max(minn1,a[i])
                    i+=1
                ans1+=minn1
                if i<n:
                    maxx1 = a[i]
                    one+=1
        if convert[n-1]==1:
            ans1+=maxx1
        print(ans1)
    elif convert[0]==0:
        zero = 1
        i = 0
        ans2 = 0
        maxx2 = a[0]
        while i<n and convert[i]==0:
            maxx2 = max(maxx2,a[i])
            i+=1
            if i<n and convert[i]==1:
                ans2+=maxx2
                zero+=1
                minn2 = a[i]
                while i<n and convert[i]==1:
                    minn2 = max(minn2,a[i])
                    i+=1
                ans2+=minn2
                if i<n:
                    maxx2 = a[i]
                    zero+=1
        if convert[n-1]==0:
            ans2+=maxx2
        print(ans2)

