for _ in range(int(input())):
    input()
    s=0
    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)