
def foo(size, arr):
    toggle = True if arr[0] > 0 else False
    rarr = 0
    i = 0
    while i<size:
        if toggle:
            j , m = i+1, arr[i]
            while j<size and arr[j] > 0:
                m = max(m,arr[j])
                j += 1
            rarr+=m
            i = j
            toggle = False
        else:
            j = i + 1
            m = arr[i]
            while j<size and arr[j] < 0:
                m = max(m,arr[j])
                j += 1
            rarr+=m
            i = j
            toggle = True

    print(rarr)



if __name__ == '__main__':
    test = int(input())
    while test:
        size = int(input())
        data = [int(i) for i in input().split()]
        foo(size, data)
        test -= 1
