t = int(input())
for i in range(t):
    n = int(input())
    a = [int(s) for s in input().split()]
    b = [a[0]]
    pre = a[0]
    for j in range(n):
        if pre * a[j] > 0 and pre > 0:
            pre = max(pre, a[j])
            b[-1] = pre
        elif pre * a[j] > 0 and pre > 0:
            pre = min(pre , a[j])
            b[-1] = pre
        elif pre * a[j] < 0:
            pre = a[j]
            b.append(pre)
    print(sum(b))
