#include <bits/stdc++.h>
using namespace std;
int _I() {
  int x;
  scanf("%d", &x);
  return x;
}
long long _ILL() {
  long long x;
  scanf("%lld", &x);
  return x;
}
struct node {
  int a, b;
  long long c;
  int d;
  node(){};
  node(int a, long long c) {
    this->a = a;
    this->c = c;
  }
  bool operator<(const node &R) const { return c > R.c; }
};
long long ar[200005];
void solve() {
  int n = _I();
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  long long pos = LLONG_MIN, neg = LLONG_MIN;
  bool p = 0, nn = 0;
  long long sum1 = 0, sum2 = 0;
  for (int i = 0; i < n;) {
    if (p == 0) {
      neg = LLONG_MIN;
      while (ar[i] < 0 && i < n) {
        neg = max(neg, ar[i]);
        i++;
      }
      p = 1;
      if (neg == LLONG_MIN) continue;
      sum1 += neg;
    }
    if (p == 1) {
      neg = LLONG_MIN;
      while (ar[i] > 0 && i < n) {
        neg = max(neg, ar[i]);
        i++;
      }
      p = 0;
      if (neg == LLONG_MIN) continue;
      sum2 += neg;
    }
  }
  long long ans1 = sum1 + sum2;
  sum1 = 0, sum2 = 0;
  p = 0;
  for (int i = 0; i < n;) {
    if (p == 0) {
      neg = LLONG_MIN;
      while (ar[i] > 0 && i < n) {
        neg = max(neg, ar[i]);
        i++;
      }
      p = 1;
      if (neg == LLONG_MIN) continue;
      sum1 += neg;
    }
    if (p == 1) {
      neg = LLONG_MIN;
      while (ar[i] < 0 && i < n) {
        neg = max(neg, ar[i]);
        i++;
      }
      p = 0;
      if (neg == LLONG_MIN) continue;
      sum2 += neg;
    }
  }
  long long ans2 = sum1 + sum2;
  printf("%lld\n", max(ans2, ans1));
}
int main() {
  int t = _I();
  while (t--) solve();
  return 0;
}
