for _ in range(int(input())):
    n = int(input())
    x = 0
    s = 0
    for y in map(int, input().split()):
        if (y < 0) == (x < 0):
            x = max(x, y)
        else:
            s += x
            x = y
    print(s + x)
