t = int(input())
for _ in range(t):
    n = int(input())
    lst = [i for i in map(int, input().split())]
    ans = [lst[0]]
    for index in range(1, n):
        if lst[index] < 0:
            if lst[index - 1] > 0:
                ans.append(lst[index])
            elif lst[index-1] < 0 and lst[index] > lst[index-1]:
                ans[len(ans)-1] = lst[index]
        else:
            if lst[index - 1] < 0:
                ans.append(lst[index])
            elif lst[index] > lst[index-1] > 0:
                ans[len(ans)-1] = lst[index]
    print(sum(ans))
