t = int(input())

for _ in range(t):
    S = 0
    n = int(input())
    m = input().split()
    sign = '-' in m[0]
    M = -1e12
    for i in m:
        i = int(i)
        if (i<0) == sign:
            M = max(M, i)
        else:
            sign = 1 - sign
            S += M
            M = i
    S += M
    print(S)
