for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    new_seq = []
    i = 0
    j = i
    if arr[j] < 0:
        temp = []
        while j < n and arr[j] < 0:
            temp.append(arr[j])
            j += 1
        new_seq.append(max(temp))
    else:
        temp = []
        while j < n and arr[j] > 0:
            temp.append(arr[j])
            j += 1
        new_seq.append(max(temp))
    i = j
    while True:
        if new_seq[-1] < 0:
            temp = []
            while j < n and arr[j] > 0:
                temp.append(arr[j])
                j += 1
            if temp == []:
                break
            new_seq.append(max(temp))
        else:
            temp = []
            while j < n and arr[j] < 0:
                temp.append(arr[j])
                j += 1
            if temp == []:
                break
            new_seq.append(max(temp))
    print(sum(new_seq))
