import sys
from collections import deque
input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

def print_list_int(l):
    # print("made to print list")
    str_list = list(map(str, list(map(int, out))))
    print(" ".join(str_list))

if __name__ == "__main__":
    t = inp()
    for test in range(t):
        n = inp()
        arr = inlt()
        stack = deque([arr[0]])
        for i in arr[1:]:
            # print(False == False)
            # print(stack)
            last = stack.pop()
            # print(i, last, i<0, last<0, (i<0)==(last<0))
            if (i < 0) == (last < 0):
                stack.append(max(last, i))
            else:
                stack.append(last)
                stack.append(i)
        print(int(sum(stack)))
