for _ in range(int(input())):
    size = int(input())
    array = list(map(int,input().split()))
    # Setting the initial state of the flag
    bag = [array[0]]; flag = 1 if bag[0] > 0 else -1
    for x in range(1,size):
        # Looking for the next negative number
        if flag == 1:
            # If a positive number appears,
            # see if it's larger than the last number appended
            if array[x] > 0:
                if array[x] > bag[-1]:
                    bag[-1] = array[x]
            else: bag.append(array[x]); flag = -1
        # Looking for the next positive number
        elif flag == -1:
            # If a negative number appears,
            # see if it's larger than the last number appended
            if array[x] < 0:
                if array[x] > bag[-1]:
                    bag[-1] = array[x]
            else: bag.append(array[x]); flag = 1
    print(sum(bag))