t = int(input())
for i in range(t):
    n = int(input())
    a = [int(_) for _ in input().split() if int(_) != 0]
    i = 0
    s = a[0] < 0
    l = len(a)
    b = []
    while i < l:
        if s:
            j = i
            while j < l and a[j] < 0:
                j += 1
            b.append(max(a[i:j]))
            i = j
            s = not s
        else:
            j = i
            while j < l and a[j] > 0:
                j += 1
            b.append(max(a[i:j]))
            i = j
            s = not s
    print(sum(b))

