t = int(input())
for i in range(t):
    N = int(input())
    row = [int(g) for g in input().split(' ')]

    if row[0] > 0:
        p_n = 1
        current = 0
    else:
        p_n = 0
        current = -float('inf')

    total = 0
    for i in range(N):
        #print(current)
        if (row[i] > 0) == p_n:
            current = max(current, row[i])
        else:
            total += current
            p_n = (p_n+1)%2
            current = row[i]
    total += current
    print(total)


