#class C:
from sys import stdin, stdout

if  __name__ == '__main__':
    n_tests = int(input())

    for k in range(n_tests):
        input()
        a = stdin.readline().split()
        a = list(map(int, a))

        sum = 0
        maxEl = a[0]
        for element in a:
            if (maxEl > 0 and element < 0) or (maxEl < 0 and element > 0):
                sum += maxEl
                maxEl = element

            maxEl = max(maxEl, element)
        sum += maxEl
        stdout.write(str(sum) + '\n')