#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int step[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
struct node {
  int x;
  int p;
};
const int mm = -109 - 2;
node a[200005], b[200005];
int c[200005], d[200005];
int main() {
  int t;
  cin >> t;
  while (t--) {
    memset(c, 0, sizeof(c));
    memset(d, 0, sizeof(d));
    int n;
    cin >> n;
    int pz = 1;
    int pf = 1;
    int m;
    for (int i = 1; i <= n; i++) {
      cin >> m;
      if (m > 0) {
        a[pz].x = m;
        a[pz].p = i;
        pz++;
      } else {
        b[pf].x = m;
        b[pf].p = i;
        pf++;
      }
    }
    int cz = 1, cf = 1;
    int ts = 0;
    for (int i = 1; i < pz; i++) {
      ts = max(ts, a[i].x);
      if (a[i].p + 1 != a[i + 1].p) {
        c[cz] = ts;
        cz++;
        ts = 0;
      }
    }
    ts = -inf;
    for (int i = 1; i < pf; i++) {
      ts = max(ts, b[i].x);
      if (b[i].p + 1 != b[i + 1].p) {
        d[cf] = ts;
        cf++;
        ts = -inf;
      }
    }
    long long sum = 0;
    for (int i = 1; i < cz; i++) {
      sum += c[i];
    }
    for (int i = 1; i < cf; i++) {
      sum += d[i];
    }
    cout << sum << '\n';
  }
  return 0;
}
