for _ in range(int(input())):
    N = int(input())
    A = list(map(int,input().split()))
    B = []
    if(A[0]>0):
        pl = "+"
    else:
        pl = "-"
    val = A[0]
    if(N==1):
        print(A[0])
    else:
        for i in range(1,len(A)):
            if(A[i]<0 and pl == "+"):
                B.append(val)
                pl = "-"
                val = A[i]
                if(i==len(A)-1):
                    B.append(val)
            elif(A[i]>0 and pl == "+"):
                val = max(val,A[i])
                if(i==len(A)-1):
                    B.append(val)
            elif(A[i]<0 and pl == "-"):
                val = max(A[i],val)
                if(i==len(A)-1):
                    B.append(val)
            elif(A[i]>0 and pl == "-"):
                B.append(val)
                pl = "+"
                val = A[i]
                if(i==len(A)-1):
                    B.append(val)
        #print(B)
        print(sum(B))