

for x in range(int(input())):
    n = int(input())
    *l, = map(int, input().split())
    r = 0; s = l[0]
    for i in range(1, n):
        if l[i] * s < 0:
            r += s
            s = l[i]
        s = max(s, l[i])
    print(r+s)


