t = int(input())
for i in range(t):
    n = int(input())
    m = list(map(int,input().split()))
    md = 1
    ms = m[0]
    d = 1
    s = m[0]
    l = m[0] // (abs(m[0]))
    ll = 0
    for j in range(1,n):
        if m[j] // (abs(m[j])) != l:
            d += 1
            s += m[j]
            l = -l
            ll = j
        else:
            if m[j] > m[ll]:
                s += m[j]
                s -= m[ll]
                ll = j
    print(s)