import math
for _ in range(int(input())):
    n = int(input())

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

    if (n == 1):
        print(arr[0])
        continue

    if(arr[0] < 0):
        curr = 0
    else:
        curr = 1

    k = 0
    segments = [[arr[0]]]

    for i in range(1, n):

        if((curr == 0 and arr[i] < 0) or (curr == 1 and arr[i] > 0)):
            segments[k].append(arr[i])
        else:
            segments.append([arr[i]])
            k += 1

            if(arr[i] < 0):
                curr = 0
            else:
                curr = 1


    maxSum = 0
    for j in segments:
        maxSum += max(j)

    print(maxSum)

