import heapq as hp
import collections
import bisect


def unpack(func=int):
    return map(func, input().split())


def l_unpack(func=int):
    """list unpack"""
    return list(map(func, input().split()))


def s_unpack(func=int):
    """sorted list unpack"""
    return sorted(map(func, input().split()))


def range_n():
    return range(int(input()))


def counter(a):
    d = {}
    for x in a:
        if x in d:
            d[x] += 1
        else:
            d[x] = 1
    return d


def getint():
    return int(input())


def same_sign(sym, x):
    return not ((sym > 0) ^ (x > 0))


def main():
    for _ in range_n():
        n = getint()
        a = l_unpack()
        sym = 1 if a[0] > 0 else -1
        ans = 0
        i = 0
        while i < n:
            temp = a[i]
            while i < n and same_sign(sym, a[i]):
                temp = max(temp, a[i])
                i += 1
            else:
                sym = 1 if sym < 0 else -1
            ans += temp
        print(ans)


main()
