t = int(input())

for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    s = 0
    buf = [a[0]]
    for ai_, ai in zip(a, a[1:]):
        if ai_ // abs(ai_) == ai // abs(ai):
            buf.append(ai)
            continue

        s += max(buf)
        buf = [ai]
    s += max(buf)
    print(s)