import random
import math

import itertools


def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        a = list(map(int, input().split()))
        sign = -1 if a[0]<0 else 1
        maxi = 0
        mini = -1000000001
        f = []
        for i in range(n):
            if sign == -1 and a[i]<0:
                mini = max(mini, a[i])
            elif sign == -1 and a[i]>0:
                f.append(mini)
                maxi = max(maxi, a[i])
                mini = -1000000001
                sign = 1
            elif sign == 1 and a[i]>0:
                maxi = max(mini, a[i])
            elif sign == 1 and a[i]<0:
                f.append(maxi)
                mini = max(mini, a[i])
                maxi = 0
                sign = -1
        if a[n-1]<0: f.append(mini)
        else: f.append(maxi)
        #print(f)
        print(sum(f))


if __name__ == "__main__":
    main()