t = int(input())
for i in range(t):
    n = int(input())
    m = list(map(int, input().split()))
    a = []
    b = []
    prev = (m[0] > 0)
    for p in m:
        if (p > 0) == prev:
            b.append(p)
        else:
            a.append(b)
            b = [p]
            prev = (p > 0)
    if b != []:
        a.append(b)
        b = []
    k = 0
    for t in a:
        k += max(t)
    print(k)













