import math


t = int(input())

while t:
    t -= 1

    n = int(input())
    s = list(map(int, input().split()))
    sum = 0
    mx = s[0]
    for i in range(1, n):
        if s[i] > 0:
            if s[i-1] < 0:
                sum += mx
                mx = s[i]
            else:
                mx = max(mx, s[i])
        else:
            if s[i-1] > 0:
                sum += mx
                mx = s[i]
            else:
                mx = max(mx, s[i])
    print(sum + mx)




