# https://codeforces.com/problemset/problem/1352/E


def main():
    n = int(input())
    arr = []
    for _ in range(n):
        temp = input()
        arr.append(list(map(int, input().split())))

    for i in range(n):
        calcSum(arr[i])


def calcSum(arr):
    lenarr = len(arr)
    total = 0
    maxn = 0
    flag = True
    for i in range(lenarr):

        if arr[i] > 0 and flag:
            maxn = max(maxn, arr[i])

        elif arr[i] < 0 and not flag:
            maxn = max(maxn, arr[i])

        else:
            total += maxn
            if arr[i] > 0:
                flag = True
                maxn = arr[i]
            else:
                flag = False
                maxn = arr[i]
    total += maxn

    print(total)


if __name__ == "__main__":
    main()
