t = int(input())
while t:
    n = int(input())
    a = [int(x) for x in input().split()]
    temp = []
    fin = []
    sign = a[0] > 0 # true for positive number
    for x in a:
        if sign:
            if x > 0: temp.append(x)
            else:
                fin.append(max(temp))
                temp = [x]
                sign = not sign
        else:
            if x < 0: temp.append(x)
            else:
                fin.append(max(temp))
                temp = [x]
                sign = not sign
    fin.append(max(temp))
    print(sum(fin))
    t -= 1