testCases = int(input())


def solve(arr):
    max_val = -100000000000000

    ans = 0
    for i in range(0, len(arr), 1):

        if int(arr[i]) < 0:
            max_val = max(max_val, int(arr[i]))

        if (int(arr[i]) > 0 or (i == len(arr) - 1) and int(arr[i] < 0)) and max_val != -100000000000000:
            ans += max_val
            max_val = -100000000000000

        if int(arr[i]) > 0 and max_val == -100000000000000:
            continue

    for i in range(0, len(arr), 1):

        if int(arr[i]) > 0:
            max_val = max(max_val, int(arr[i]))

        if (int(arr[i]) < 0 or (i == len(arr) - 1) and int(arr[i] > 0)) and max_val != -100000000000000:
            ans += max_val
            max_val = -100000000000000

        if int(arr[i]) < 0 and max_val == -100000000000000:
            continue

    return ans


while testCases:
    n = int(input())
    arr = list(map(int, input().split()))

    print(solve(arr))
    testCases -= 1
