Recall that the sequence $b$ is a a subsequence of the sequence $a$ if $b$ can be derived from $a$ by removing zero or more elements without changing the order of the remaining elements. For example, if $a=[1, 2, 1, 3, 1, 2, 1]$, then possible subsequences are: $[1, 1, 1, 1]$, $[3]$ and $[1, 2, 1, 3, 1, 2, 1]$, but not $[3, 2, 3]$ and $[1, 1, 1, 1, 2]$.

You are given a sequence $a$ consisting of $n$ positive and negative elements (there is no zeros in the sequence).

Your task is to choose maximum by size (length) alternating subsequence of the given sequence (i.e. the sign of each next element is the opposite from the sign of the current element, like positive-negative-positive and so on or negative-positive-negative and so on). Among all such subsequences, you have to choose one which has the maximum sum of elements.

In other words, if the maximum length of alternating subsequence is $k$ then your task is to find the maximum sum of elements of some alternating subsequence of length $k$.

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9, a_i \ne 0$), where $a_i$ is the $i$-th element of $a$.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).


-----Output-----

For each test case, print the answer — the maximum sum of the maximum by size (length) alternating subsequence of $a$.


-----Example-----
Input
4
5
1 2 3 -1 -2
4
-1 -2 -1 -3
10
-2 8 3 8 -4 -15 5 -2 -3 1
6
1 -1000000000 1 -1000000000 1 -1000000000

Output
2
-1
6
-2999999997



-----Note-----

In the first test case of the example, one of the possible answers is $[1, 2, \underline{3}, \underline{-1}, -2]$.

In the second test case of the example, one of the possible answers is $[-1, -2, \underline{-1}, -3]$.

In the third test case of the example, one of the possible answers is $[\underline{-2}, 8, 3, \underline{8}, \underline{-4}, -15, \underline{5}, \underline{-2}, -3, \underline{1}]$.

In the fourth test case of the example, one of the possible answers is $[\underline{1}, \underline{-1000000000}, \underline{1}, \underline{-1000000000}, \underline{1}, \underline{-1000000000}]$.
[{"code": "for _ in range(int(input())):\n    n=int(input())\n    l=list(map(int,input().split()))\n    a=[]\n    lis=[]\n    prevsign=-1\n    if l[0]>0:\n        prevsign=1\n    else:\n        prevsign=0\n    i=0\n    for i in l:\n        if (i>0 and prevsign==1) or (i<0 and prevsign==0):\n            lis.append(i)\n        else:\n            if prevsign==1:\n                a.append(max(lis))\n                lis=[]\n                lis.append(i)\n                prevsign=0\n            else:\n                a.append(max(lis))\n                lis=[]\n                lis.append(i)\n                prevsign=1\n    \n    if prevsign==1:\n        a.append(max(lis))\n        lis=[]\n        lis.append(i)\n        prevsign=0\n    else:\n        a.append(max(lis))\n        lis=[]\n        lis.append(i)\n        prevsign=1\n    print(sum(a))\n        \n", "passed": true, "time": 0.14, "memory": 14196.0, "status": "done"}, {"code": "t = int(input())\nfor _ in range(t):\n    n = int(input())\n    a = list(map(int,input().split()))\n    b = [a[0]]\n    ans = 0\n    for i in range(1,n):\n        if b[0] < 0 and a[i] < 0:\n            b.append(a[i])\n        if b[0] > 0 and a[i] > 0:\n            b.append(a[i])\n        if b[0] < 0 and a[i] > 0:\n            ans += max(b)\n            b = [a[i]]\n        if b[0] > 0 and a[i] < 0:\n            ans += max(b)\n            b = [a[i]]\n    if len(b) >= 1:\n        ans += max(b)\n    print(ans)\n\n# a = list(map(int,input().split()))\n# n,m = map(int,input().split())\n\n\n", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "for i in range(int(input())):\n\tn=int(input())\n\ta=[int(j) for j in input().split()]\n\ts=0\n\tmx=a[0]\n\tfor j in range(n):\n\t\tif(a[j]*mx<0):\n\t\t\ts+=mx\n\t\t\tmx=a[j]\n\t\telse:\n\t\t\tmx=max(mx, a[j])\n\tprint(s+mx)", "passed": true, "time": 0.22, "memory": 14160.0, "status": "done"}, {"code": "for _ in range(int(input())):\n    n = int(input())\n    a = list(map(int, input().split()))\n\n    i = 1\n    b, tmp = [], [a[0]]\n    while i < n:\n        if a[i] * tmp[0] > 0:\n            tmp.append(a[i])\n        else:\n            b.append(tmp)\n            tmp = [a[i]]\n        i += 1\n\n    b.append(tmp)\n\n    s = 0\n    for bb in b:\n        s += max(bb)\n\n    print(s)\n", "passed": true, "time": 0.14, "memory": 14236.0, "status": "done"}, {"code": "import sys\nlines = sys.stdin.readlines()\nT = int(lines[0].strip())\nfor t in range(T):\n    n = int(lines[2*t+1].strip())\n    nums = list(map(int,  lines[2*t+2].strip().split(\" \")))\n    res = []\n    tmp = nums[0]\n    for i in range(1, len(nums)):\n        if nums[i] * nums[i-1] > 0:\n            tmp = max(tmp, nums[i])\n        else:\n            res.append(tmp)\n            tmp = nums[i]\n    res.append(tmp)\n    print(sum(res))\n", "passed": true, "time": 0.14, "memory": 14188.0, "status": "done"}, {"code": "from sys import stdin\ninput = stdin.readline\nt = int(input())\nfor rew in range(t):\n\tn = int(input())\n\tl = list(map(int,input().split()))\n\twyn = 0\n\tlistka = []\n\tcur = [l[0]]\n\tfor i in range(1,n):\n\t\tif cur and l[i] * cur[-1] < 0:\n\t\t\tlistka.append(cur)\n\t\t\tcur = [l[i]]\n\t\telse:\n\t\t\tcur.append(l[i])\n\tlistka.append(cur)\n\tfor i in listka:\n\t\twyn += max(i)\n\tprint(wyn)", "passed": true, "time": 0.14, "memory": 14260.0, "status": "done"}, {"code": "t = int(input())\nfor tt in range(t):\n\tn = int(input())\n\ta = list(map(int, input().split()))\n\ts = a[0]\n\tl = a[0]\n\tfor i in range(1, n):\n\t\tif a[i] > 0 and l < 0 or a[i] < 0 and l > 0:\n\t\t\tl = a[i]\n\t\t\ts += l\n\t\telif l < a[i]:\n\t\t\ts += a[i] - l\n\t\t\tl = a[i]\n\tprint(s)", "passed": true, "time": 0.14, "memory": 14236.0, "status": "done"}, {"code": "t=int(input())\nfor pp in range(0,t):\n    n=int(input())\n    ip=list(map(int,input().split()))\n    if(ip[0]>0):\n        arr=[]\n        curr=ip[0]\n        sign=1\n        for i in range(1,len(ip)):\n            num=ip[i]\n            if(num>0 and sign==1 and num>curr):\n                curr=num\n            elif(num<0 and sign==1):\n                arr.append(curr)\n                curr=num\n                sign=-1\n            elif(sign==-1):\n                if(num<0 and num>curr):\n                    curr=num\n                if(num>0):\n                    arr.append(curr)\n                    curr=num\n                    sign=1\n        arr.append(curr)\n    else:\n        arr=[]\n        curr=ip[0]\n        sign=-1\n        for i in range(1,len(ip)):\n            num=ip[i]\n            if(num>0 and sign==1 and num>curr):\n                curr=num\n            elif(num<0 and sign==1):\n                arr.append(curr)\n                curr=num\n                sign=-1\n            elif(sign==-1):\n                if(num<0 and num>curr):\n                    curr=num\n                if(num>0):\n                    arr.append(curr)\n                    curr=num\n                    sign=1\n        arr.append(curr)\n    ss=sum(arr)\n    print(ss)", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "t = int(input())\nfor i in range(t):\n    n = int(input())\n    a = [int(i) for i in input().split()]\n    ans = 0\n    index = 0\n    now = a[0]\n    mx = a[0]\n    while index < n:\n        while index < n and now * a[index] > 0:\n            mx = max(mx, a[index])\n            index += 1\n        ans += mx\n        if index == n:\n            break\n        now = a[index]\n        mx = a[index]\n    print(ans)\n", "passed": true, "time": 0.14, "memory": 14220.0, "status": "done"}, {"code": "t = int(input())\n\nfor _ in range(t):\n    n = int(input())\n    a = [int(x) for x in input().strip().split()]\n    i = 0\n    res = 0\n    while i<n:\n        if a[i]>0:\n            pi = 0 \n            while i<n and a[i]>0:\n                pi = max(pi, a[i])\n                i+=1\n                \n            res+=pi\n        else:\n            ni = -10**10\n            while i<n and a[i]<0:\n                ni = max(ni,a[i])\n                i+=1\n            res+=ni\n    print(res)", "passed": true, "time": 0.57, "memory": 14288.0, "status": "done"}, {"code": "t = int(input())\nfor i in range(t):\n    n = int(input())\n    a = list(map(int, input().split()))\n    ind = 0\n    ans = 0\n    while ind < n:\n        cur = -10000000001\n        if a[ind] < 0:\n            while ind < n and a[ind] < 0:\n                cur = max(a[ind], cur)\n                ind += 1\n        else:\n            while ind < n and a[ind] > 0:\n                cur = max(a[ind], cur)\n                ind += 1\n        ans += cur\n    print(ans)", "passed": true, "time": 0.14, "memory": 14164.0, "status": "done"}, {"code": "t=int(input())\nfor i in range(t):\n    n=int(input())\n    nums=list(map(int,input().split()))\n    currentmax=nums[0]\n    ans=0\n    if nums[0]>0:\n        pos=1\n    else:\n        pos=-1\n    for j in range(1,n):\n        if nums[j]>0:\n            if pos==1:\n                if nums[j]>currentmax:\n                    currentmax=nums[j]\n            else:\n                ans=ans+currentmax\n                currentmax=nums[j]\n                pos=1\n        else:\n            if pos==-1:\n                if nums[j]>currentmax:\n                    currentmax=nums[j]\n            else:\n                ans=ans+currentmax\n                currentmax=nums[j]\n                pos=-1\n    ans=ans+currentmax\n    print(ans)", "passed": true, "time": 0.14, "memory": 14172.0, "status": "done"}]