import sys
input = sys.stdin.readline
ans = []
t = int(input())
for _ in range(t):
    n = int(input())
    a = [int(x) for x in input().split()]
    ans = []
    if a[0] > 0:
        tmp = a[0]
        switch = 1
    else:
        tmp = a[0]
        switch = 0
    for i in a[1:]:
        if switch and i > 0:
            tmp = max(tmp, i)
        elif switch and i < 0:
            ans.append(tmp)
            tmp = i
            switch = 0
        elif not switch and i < 0:
            tmp = max(tmp, i)
        else:
            ans.append(tmp)
            tmp = i
            switch = 1
    ans.append(tmp)
    print(sum(ans))
