t = int(input())
for t in range(t):
    n = int(input())
    a = [int(x) for x in input().split()]
    sign = []
    for i in range(n):
        if a[i] > 0:
            sign.append(1)
        else:
            sign.append(-1)
    i = 0
    result = []
    while i < n:
        j = i
        temp = a[i]
        while j < n and sign[i] == sign[j]:
            temp = max(temp,a[j])
            j += 1
        result.append(temp)
        i = j - 1
        i += 1
    print(sum(result))