m = int(input())
for i in range(m):
    n = int(input())
    a = list(map(int, input().split()))
    s = 0
    max = a[0]
    for x in a:
        if x * max > 0 and x > max:
            max = x
        elif x * max < 0:
            s += max
            max = x
    s += max
    print(s)
