t = int(input())
for i in range(t):
    n = int(input())
    a = [int(k) for k in input().split()]
    m = 0
    m1 = -10000000000
    s = 0
    for j in a:
        if j > 0:
            if m1 != -10000000000:
                s += m1
            m1 = -10000000000
            m = max(m, j)
        if j < 0:
            if m != 0:
                s += m
            m = 0
            m1 = max(m1, j)
    if a[n-1] > 0:
        print(s + m)
    if a[n-1] < 0:
        print(s + m1)


