
for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    summ = 0
    count = 0
    l = 0
    for i in range(n):
        if i == 0:
            summ1 = summ+a[i]
        else:
            if ((a[i]>0)and(a[i-1]>0) or (a[i]<0 and a[i-1]<0)):
                if summ + a[i] > summ1:
                    summ1 = summ + a[i]
                    if a[i] > 0:
                        l =a[i]
            else:
                summ1 = summ1 + a[i]
                count += 1
                summ = summ1 - a[i]
    print(summ1)
    