''' Alternating Subsequence
'''



''' routine '''

T = int(input())

for test in range(T):
    N = int(input())
    array = list(map(int, input().split()))

    if N == 1:
        print(array[0])
        continue
    
    cur = array[0]
    if cur > 0:
        sign = 1
    else:
        sign = -1

    total = 0
    amax = cur
    for n in range(1, N):
        if array[n]*array[n - 1] > 0:
            amax = max(amax, array[n])
        else:
            total += amax
            amax = array[n]

        if n == N - 1:
            total += amax
    print(total)