T = int(input())
for _ in range(T):
    n = int(input())
    l = list(map(int, input().split()))
    a = []
    last = -1
    maxx = int(-1e12)
    minn = int(1e12)
    for i in l:
        if i>0:
            if last == -1:
                last = 0
                maxx = i
            elif last == 0:
                maxx = max(i,maxx)
            else:
                a.append(minn)
                minn = int(1e12)
                maxx = i
                last = 0
        else:
            if last == -1:
                last = 1
                minn = i
            elif last == 1:
                minn = max(i,minn)
            else:
                a.append(maxx)
                maxx = int(-1e12)
                minn = i
                last = 1
    if last == 0:
        a.append(maxx)
    else:
        a.append(minn)
    print(sum(a))
