import sys
from array import array  # noqa: F401
import typing as Tp  # noqa: F401


def input():
    return sys.stdin.buffer.readline().decode('utf-8')


def main():
    t = int(input())
    ans = [''] * t

    for ti in range(t):
        n = int(input())
        a = [0] + list(map(int, input().split())) + [0]
        total, x = 0, 0

        for prev, cur in zip(a, a[1:]):
            if prev * cur <= 0:
                total += x
                x = cur
            else:
                x = max(x, cur)

        ans[ti] = str(total)

    sys.stdout.buffer.write(('\n'.join(ans) + '\n').encode('utf-8'))


if __name__ == '__main__':
    main()
