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