for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    res = arr[0]
    cur = arr[0]
    for i in range(1, n):
        if cur > 0:
            if arr[i] > cur:
                res = res - cur + arr[i]
                cur = arr[i]
            if arr[i] < 0:
                cur = arr[i]
                res = res + cur
        else:
            if arr[i] > 0:
                cur = arr[i]
                res = res + cur
            elif arr[i] > cur:
                res = res - cur + arr[i]
                cur = arr[i]
    print(res)