for _ in range(int(input())):
    input()
    s = x = 0
    for a in map(int, input().split()):
        if a*x > 0:
            x = max(x,a)
        else:
            s += x
            x = a
    print(s+x)