

t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    s1 = 0
    s2 = 0
    e1 = a[0]
    e2 = 0
    k1 = 1
    k2 = 0
    flag = False
    for i in range(1, n):
        if (a[i] < 0 and e1 < 0) or (a[i] > 0 and e1 > 0):
            e1 = max(e1, a[i])
        else:
            k1 += 1
            if not flag:
                e2 = a[i]
                k2 = 1
                flag = True
            s1 += e1
            e1 = a[i]

        if flag:
            if (a[i] < 0 and e2 < 0) or (a[i] > 0 and e2 > 0):
                e2 = max(e2, a[i])
            else:
                k2 += 1
                s2 += e2
                e2 = a[i]

    s1 += e1
    s2 += e2
    if k1 == k2:
        print(max(s1, s2))
    elif k1 > k2:
        print(s1)
    else:
        print(s2)
