for _ in range(int(input())):
    n = int(input())
    x = list(map(int, input().split()))
    s = 0
    p = [x[0]]
    for i in range(1, n):
        if (x[i] > 0 and x[i - 1] > 0) or (x[i] < 0 and x[i - 1] < 0):
            p.append(x[i])
        else:
            s += max(p)
            p = [x[i]]

    print(s + max(p))   
