a = int(input())
for x in range(a):
    a = int(input())
    b = [int(x) for x in input().split()]
    x = 0
    answer = 0
    while x < len(b):
        extreme = 0
        while b[x] < 0:
            if extreme == 0 or extreme < b[x]:
                extreme = b[x]
            x += 1
            if x == len(b):
                break
        answer += extreme
        extreme = 0
        if x < len(b):
            while b[x] > 0:
                if extreme == 0 or extreme < b[x]:
                    extreme = b[x]
                x += 1
                if x == len(b):
                    break
        answer += extreme
    print(answer)