t= int(input())
for z in range(t):
    n = int(input())
    l = [int(i) for i in input().split()]
    p = False
    maxn = -9999999999
    maxp = 0
    summ = 0
    if(l[0]> 0):
        p = True
    for i in range(0,n):
        if(l[i] < 0):
            if(p):
                summ += maxp
                maxn = -9999999999
                maxp = 0
            p = False
            if(maxn < l[i]):
                maxn = l[i]
        if(l[i] > 0):
            if(not p):
                summ += maxn
                maxn = -9999999999
                maxp = 0
            p = True
            if(maxp < l[i]):
                maxp = l[i]
    if(p):
        summ  += maxp
    else:
        summ += maxn
    print(summ)