T = int(input())

for _ in range(T) :
    n = int(input())
    a = list(map(int, input().split(' ')))
    k = 1
    res = 0
    best = a[0]
    prev = 1 if a[0] > 0 else -1
    for val in a[1:] :
        cur = 1 if val > 0 else -1
        if prev != cur :
            res += best
            best = val
            k += 1
            prev = cur
        else :
            best = max(best, val)
    res += best
    print(res)
