T = int(input())

for t in range(T):

    n = int(input())

    values = list(map(int , input().split()))

    value = 0

    i = 0
    while(i < n-1):

        j = i
        ans = values[i]

        while((values[i]//abs(values[i]))*(values[j]//abs(values[j])) > 0):
            ans = max(ans , values[j])
            j += 1
            if j>= n:
                break

        value += ans
        i = j

    #if 

    if n == 1:
        print(values[0])

    elif values[n-1] *values[n-2] < 0:
        value += values[n-1]
        print(value)

    else:
        print(value)