t = int(input())
for i in range(t):
    n = int(input())
    lst = list(map(int, input().split()))
    max = lst[0]
    tot = 0
    for j in range(1,n):
        if max/lst[j]<0:
            tot += max
            max = lst[j]
        elif lst[j] > max:
            max = lst[j]
    tot += max
    print(tot)