def solve(n, a):
    i, j, s = 0, 0, 0
    while i < n:
        m = -float('INF')
        while j < n and a[i]*a[j] > 0:
            m = max(m, a[j])
            j += 1
        s += m
        i = j
    return s


def main():
    tc = int(input())
    for _ in range(tc):
        n = int(input())
        a = [int(x) for x in input().split()]
        print(solve(n, a))


if __name__ == '__main__':
    main()
