t = int(input())

for _ in range(t):
    l = int(input())
    a = list(map(int, input().split()))
    c = 0
    m = a[0]
    for i in range(l-1):
        if a[i] * a[i+1] > 0:
            m = max(m, a[i+1])
        else:
            c += m
            m = a[i+1]

    c += m

    if a[-1] * m < 0:
        c += a[-1]

    print(c)
