n = int(input())
for i in range(n):
    length = int(input())
    myList = input().split()
    maxLength = 1
    ans = 0
    maxNum = int(myList[0])
    for i in range(len(myList)-1):
        if int(myList[i+1]) > 0 and int(myList[i]) < 0:
            maxLength += 1
            ans += maxNum
            maxNum = int(myList[i+1])
        elif (int(myList[i+1]) < 0 and int(myList[i]) > 0):
            maxLength += 1
            ans += maxNum
            maxNum = int(myList[i+1])
        else:
            if int(myList[i+1]) > maxNum:
                maxNum = int(myList[i+1])
        if i == len(myList)-2:
            ans += maxNum
        
    print(ans)
        
