for _ in range (int(input())):
    n = int(input())
    l = list(map(int, input().split()))
    k = []
    i = 0
    while(i < n):
        if l[i] < 0:
            m = -999999999999
            while (l[i] < 0):
                m = max(m, l[i])
                i += 1
                if i == n:
                    break
            k.append(m)
        else:
            m = 0
            while (l[i] > 0):
                m = max(m, l[i])
                i += 1
                if i == n:
                    break
            k.append(m)
    print(sum(k))