def startPostve(arr):
    sum = 0
    max  = 0
    max1 = -float('inf')

    for i in range(len(arr)):
        if arr[i] > 0:
            if max1 != -float('inf'):
                sum+=max1
                max1 = -float('inf')

            if max < arr[i]:
                max = arr[i]
        else:
            if max !=0:
                sum+=max
                max = 0
            if max1 < arr[i]:
                max1 = arr[i]
    if max!=0:
        sum+=max
    if max1!=-float('inf'):
        sum+=max1
    return sum

def startNegtve(arr):
    sum = 0
    max  = 0
    max1 = -float('inf')

    for i in range(len(arr)):
        if arr[i] < 0:
            if max!=0:
                sum+=max
                max=0
            if max1 < arr[i]:
                max1 = arr[i]
        else:
            if max1!=-float('inf'):
                sum+=max1
                max1 = -float('inf')
            if max < arr[i]:
                max = arr[i]

    if max!=0:
        sum+=max
    if max1!=-float('inf'):
        sum+=max1
    return sum

def alternatingSub(arr):
    if arr[0] > 0:
        print(startPostve(arr))
    else:
        print(startNegtve(arr))


def main():
    t = int(input())
    for i in range(t):
        input()
        arr = list(map(int, input().split()))
        alternatingSub(arr)

main()
