for _ in range(int(input())):
    sgn = lambda x: 1 if x > 0 else -1
    lens = int(input())
    arrs = [int(x) for x in input().split()]
    sums = 0
    i = 0
    while i < lens:
        now = arrs[i]
        j = i
        while j < lens and sgn(now) == sgn(arrs[j]):
            now = max(now, arrs[j])
            j += 1
        sums += now
        i = j
        #print(sums, now, i, j)
    print(sums)
