t = int(input())


for k in range(t):
    n = input()
    a = list(map(int, input().split()))
    pre = 0
    sub = 0
    sum = 0
    for i in a:

        if i > 0 >= pre:
            sub += 1
            sum += pre
            pre = i
        elif i < 0 <= pre:
            sub += 1
            sum += pre
            pre = i

        elif i > pre:
            pre = i

    sum += pre

    print(sum)
