t = int(input())
while t:
    n = int(input())
    a = list(map(int, input().split()))
    sign = 'p' if a[0] > 0 else 'n'
    it = 0
    maxi = -float('inf')
    mini = maxi
    while it < n:
        if sign == 'p' and a[it] > 0:
            maxi = max(maxi, a[it])
        elif sign == 'n' and a[it] < 0:
            mini = max(mini, a[it])
        else:
            break
        it += 1
    ans = maxi if sign == 'p' else mini
    if it < n:
        sign = 'p' if a[it] > 0 else 'n'
    while it < n:
        flag1 = 0
        maxi = -float('inf') if sign == 'p' else maxi
        while sign == 'p' and a[it] > 0:
            maxi = max(maxi, a[it])
            it += 1
            flag1 = 1
            if it == n:
                break
        if flag1:
            # print(maxi)
            ans += maxi
            flag1 = 0
        if it == n:
            break
        # print(ans)
        sign = 'p' if a[it] > 0 else 'n'
        flag2 = 0
        mini = -float('inf') if sign == 'n' else mini
        while sign == 'n' and a[it] < 0:
            mini = max(mini, a[it])
            it += 1
            flag2 = 1
            if it == n:
                break
        if flag2:
            ans += mini
            flag2 = 0
        if it == n:
            break
        sign = 'p' if a[it] > 0 else 'n'

    print(ans)
    t = t - 1
