def inti():
    return int(input())

def extrema(L, max):
    if max:
        M = L[0]
        for e in L:
            if e > M:
                M = e
        return M
    else:
        M = L[0]
        for e in L:
            if e < M:
                M = e
        return M

T = inti()
for t in range(1, T+1):
    n = inti()
    s = input().split(" ")
    alt = []
    positive = None
    for e in s:
        num = int(e)
        if num > 0:
            if positive == True:
                alt[-1].append(num)
            else:
                alt.append([num])
                positive = True
        else:
            if positive == False:
                alt[-1].append(num)
            else:
                alt.append([num])
                positive = False
    SUM = 0
    for sublist in alt:
        SUM += extrema(sublist, max=True)
    print(SUM)
