
for _ in range(int(input())):
    N = int(input())
    List = [int(x) for x in input().split()]
    L = []
    L.append(0)
    if(List[0]>0):
        plus = 1
    else:
        plus = -1
    for i in range(N):
        if(List[i]>0 and plus==-1):
            L.append(i)
            plus =1
        elif(List[i]<0 and plus==1):
            L.append(i)
            plus = -1
    L.append(N)
    Ans = 0
    i = 0
    for _ in range(int((len(L)-1)//2)):
        Ans+=max(List[L[i]:L[i+1]])

        Ans+=max(List[L[i+1]:L[i+2]])

        i += 2
    if(List[-1]<0):
        x = -1
        Max = -(10**9 + 7)
    else:
        x = 1
        Max = -(10**9 + 7)
    if(not len(L)&1):
        if(x==1):
            for i in range(N-1,0,-1):
                if(List[i]>0):
                    Max = max(Max,List[i])
                else:
                    
                    break
        else:
            for i in range(N-1,0,-1):
                if(List[i]<0):
                    Max = max(Max,List[i])
                else:
                    break
        if(Max!=-(10**9 + 7)):
            Ans+=Max
    print(Ans)

            