#include <bits/stdc++.h>
using namespace std;
const int maxn = 200007;
int T, N;
long long A[maxn];
long long ans1, ans2;
int main() {
  scanf("%d", &T);
  while (T--) {
    ans1 = ans2 = 0;
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) scanf("%lld", &A[i]);
    long long op = 0, tmp = -1e18;
    for (int i = 1; i <= N; i++) {
      tmp = -1e18;
      if (op == 1)
        while (i <= N && A[i] < 0) tmp = max(A[i], tmp), ++i;
      else
        while (i <= N && A[i] >= 0) tmp = max(A[i], tmp), ++i;
      if (i != N + 1) i--;
      ans1 += tmp;
      op ^= 1;
    }
    op = 1;
    for (int i = 1; i <= N; i++) {
      tmp = -1e18;
      if (op == 1)
        while (i <= N && A[i] < 0) tmp = max(A[i], tmp), ++i;
      else
        while (i <= N && A[i] >= 0) tmp = max(A[i], tmp), ++i;
      if (i != N + 1) i--;
      ans2 += tmp;
      op ^= 1;
    }
    printf("%lld\n", max(ans1, ans2));
  }
}
