test = int(input())
for peradaban in range(test):
    n = int(input())
    a = list(map(int, input().split()))
    curmax = -1e10
    ans = 0
    signum = False
    if(a[0] < 0):
        signum = True
    for i in a:
        if(signum == True):
            if(i > 0):
                ans += curmax
                curmax = i
                signum = False
            else:
                curmax = max(curmax, i)
        else:
            if(i < 0):
                ans += curmax
                curmax = i
                signum = True
            else:
                curmax = max(curmax, i)
    ans += curmax
    print(int(ans))
