from sys import stdin


a=int(stdin.readline())

for k in range(0,a):
    b = int(stdin.readline())

    c=stdin.readline().split()

    if b==1:
        print(c[0])
        continue

    best=int(c[0])
    bestsum=0

    for k in range(1,b):
            if int(c[k])*int(c[k-1])<0:
                bestsum=bestsum+best
                best=int(c[k])
                if k==b-1:
                   bestsum=bestsum+best
            else:
                if int(c[k])>int(c[k-1]):
                    best=int(c[k])
                if k==b-1:
                   bestsum=bestsum+best

    print(bestsum)