for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    li = [a[0]]
    for i in range(1, n):
        if a[i] * a[i - 1] > 0:
            li[-1] = max(li[-1], a[i])
        else:
            li.append(a[i])
    print(sum(li))