t = int(input())
b = []
for i in range(t):
    n = int(input())
    a = input().split(" ")
    for j in range(n):
        a[j] = int(a[j])
    rez = a[0]
    k = a[0]
    for d in range(n):
        if k<0:
            if a[d]>0:
                rez = rez +a[d]
                k = a[d]
            elif a[d]>k:
                rez = rez - k + a[d]
                k = a[d]
        else:
            if a[d]<0:
                rez = rez +a[d]
                k = a[d]
            elif a[d]>k:
                rez = rez - k + a[d]
                k = a[d]
    b.append(rez)

for i in range(len(b)):
    print((b[i]))