import math

T = int(input())
for _ in range(T):
    n = int(input())
    a = [int(x) for x in input().split()]
    runningsign = 0
    summaximisingnum = 0
    maxsum = 0
    sumUpdateleft = False
    
    def getSign(x):
        return int(x/abs(x))
    
    for i in range(len(a)):
        if getSign(a[i]) != runningsign:
            runningsign = getSign(a[i])
            maxsum += summaximisingnum
            summaximisingnum = a[i]
        else:
            summaximisingnum = max(summaximisingnum, a[i])
    maxsum += summaximisingnum
    print(maxsum)