t = int(input())
for _ in range(t):
    n = int(input())
    v = list(map(int, input().split(" ")))
    old = 0
    p_sum = 0
    for k in range(n):

        if old == 0:
            old = v[k]
            if k == n-1:
                p_sum += old

        elif old*v[k] < 0:
            p_sum += old
            old = v[k]
            if k == n-1:
                p_sum += old


        else:
            if v[k] > old:
                old = v[k]
            if k == n-1:
                p_sum += old
    print(p_sum)
