# 1
T = int(input())
ans = []
for t in range(T):
    n = int(input())
    a = [int(i) for i in input().split()]
    dic = []
    i = 0
    while i < n:
        j = i
        ex = a[j]
        while j + 1 < n and (a[j + 1] < 0) == (a[j] < 0):
            j += 1
            ex = max(ex, a[j])
        dic.append(ex)
        i = j + 1
    ans.append(sum(dic))

for a in ans:
    print(a)
