t = int(input())
for i in range(t):
    n = int(input())
    l = list(map(int,input().split()))
    l1 =[]
    l1.append(l[0])
    for j in l:
        le = len(l1)-1
        if l1[le]>0:
            if l1[le]>=j and j>0:
                pass
            elif l1[le]<j and j>0:
                l1.pop()
                l1.append(j)
            else:
                l1.append(j)
        else:
            if l1[le]>=j and j<0:
                pass
            elif l1[le]<j and j<0:
                l1.pop()
                l1.append(j)
            else:
                l1.append(j)
    print(sum(l1))