for tc in range(int(input())):
    n = int(input())
    arr = []
    line = input().split()
    for i in range(n):
        arr.append(int(line[i]))
    if n == 1:
        print(int(line[i]))
        continue
    count = 0
    cur = arr[0]
    summ = 0
    i = 1
    while(i<n):
        if i == n-1:
            if arr[i] > 0 and cur < 0:
                summ += arr[i]
                summ += cur
            elif arr[i] > 0 and cur > 0:
                if arr[i] > cur:
                    summ += arr[i]
                else:
                    summ += cur
            elif arr[i] < 0 and cur > 0:
                summ += arr[i]
                summ += cur
            elif arr[i] < 0 and cur < 0:
                if arr[i] > cur:
                    summ += arr[i]
                else:
                    summ += cur
            break

        if arr[i] > 0 and cur > 0:
            if arr[i] > cur:
                cur = arr[i]

        elif arr[i] < 0 and cur < 0:
            if arr[i] > cur:
                cur = arr[i]

        elif arr[i] > 0 and cur < 0:
            summ += cur
            # print(arr[i-1])
            cur = arr[i]

        elif arr[i] < 0 and cur > 0:
            summ += cur
            # print(arr[i-1])
            cur = arr[i]
        
        i += 1
        
    print(summ)