def s():
    n = int(input())
    a = list(map(int,input().split(" ")))
    pos = False
    neg = False
    pos_max = -1
    neg_max = -10e10
    sm = 0
    for x in a:
        if x*-1>0:
            if pos_max != -1:
                sm += pos_max
                pos_max = -1
            neg = True
            pos = False
        else:
            if neg_max != -10e10:
                sm += neg_max
                neg_max = -10e10
            pos = True
            neg = False
        if pos:
            pos_max = max(x,pos_max)
        else:
            neg_max = max(x,neg_max)

    if pos:
        sm += pos_max
    else:
        sm += neg_max
    print(sm)
    
t = int(input())
for i in range(t):
    s()