t = int(input())

for tc in range(t):

    n = int(input())
    arr = [int(z) for z in input().split()]

    pos, neg = [], []
    poscheckinv, negcheckinv = 0, 0

    for i in range(n):
        if arr[i] > 0:
            poscheckinv += 1
        else:
            negcheckinv += 1

    if negcheckinv == 0 or poscheckinv == 0:
        print(-1)
        continue

    #p = (arr[0] > 0)
    #print(p)
    curr = 0
    k = 1
    groups = {}
    groups[0] = arr[0]
    for i in range(1, n):
        if (arr[i] > 0 and arr[i-1] > 0) or (arr[i] < 0 and arr[i-1] < 0):
            groups[curr] = max(groups[curr], arr[i])
        else:
            curr += 1
            groups[curr] = arr[i]

    res = 0

    for i in groups:
        res += groups[i]

    print(res)


