t = int(input())
for i in range(t):
    n = int(input())
    l = list(map(int, input().split()))
    S = 0
    a = False
    for j in range(1, n):
        if l[j] > 0:
            if l[j - 1] < 0:
                if a == False:
                    S += l[j] + l[j - 1]
                    a = True
                else:
                    S += l[j]
            else:
                continue
        else:
            if l[j - 1] > 0:
                if a == False:
                    S += l[j] + l[j - 1]
                    a = True
                else:
                    S += l[j]
            else:
                continue
    if a == False:
        print(sorted(l)[-1])
    else:
        print(S)