t = int(input())
for i in range(t):
    n = int(input())
    a = [int(i) for i in input().split()]
    if a[0] < 0:
        p = -1
    else:
        p = 1
    mi = -10000000000
    ma = -1
    re = 0
    for i in range(n):
        if a[i] < 0:
            if p == -1:
                if a[i] > mi:
                    mi = a[i]
            else:
                re += ma
                p = -1
                ma = -1
                if a[i] > mi:
                    mi = a[i]
        if a[i] > 0:
            if p == -1:
                re += mi
                mi = -10000000000
                p = 1
                if a[i] > ma:
                    ma = a[i]
            else:
                if a[i] > ma:
                    ma = a[i]
    if p < 0:
        re += mi
    else:
        re += ma
    print(re)
