t = int(input())
for test in range(t):
    n = int(input())
    a = [int(x) for x in input().split()]
    max_so_far = a[0]
    curr_max = a[0]
    pos = 0
    neg = 0
    if a[0] > 0:
        pos = a[0]
        last = 1
    else:
        neg = a[0]
        last = -1
    first = 0
    i = 1
    ans = []
    ans.append(a[0])
    while i < n:
        if last == 1:
            if a[i] < 0:
                ans.append(a[i])
                last = -1
            else:
                if a[i] > ans[-1]:
                    ans.pop()
                    ans.append(a[i])

        else:

            if a[i] > 0:
                ans.append(a[i])
                last = 1
            else:
                if a[i] > ans[-1]:
                    ans.pop()
                    ans.append(a[i])
        #print(ans)
        i += 1

    #return max_so_far
    print(sum(ans))
