def getMax(s):
    summ = 0
    i = 0
    while (i < len(s)):
        temp, r1, r2 = s[i], False, False
        while i < len(s) and s[i] < 0:
            r1 = True
            if (s[i] > temp):
                temp = s[i]
            i += 1
        if r1: summ += temp
        while i < len(s) and s[i] > 0:
            r2 = True
            if s[i] > temp:
                temp = s[i]
            i += 1
        if r2: summ += temp
    return summ

n = int(input(''))
for arr in range(0,n):
    _ = input('')
    array = input('').split()
    print(getMax([int(i) for i in array]))