#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long temp;
  if (a < b) {
    temp = b;
    b = a;
    a = temp;
  }
  if (a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}
long long lcm(long long a, long long b, long long c, long long d) {
  long long temp;
  if (a < b) {
    temp = b;
    b = a;
    a = temp;
  }
  if (a % b == 0) {
    return (c * d) / b;
  }
  return lcm(b, a % b, c, d);
}
const double pi = 3.14159265358979323846;
int main() {
  long long i, j, k, z, t, n, f, ans, ma, mi, a, b, c, d, x;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<long long> v;
    for (i = 0; i < n; i++) {
      cin >> x;
      v.push_back(x);
    }
    k = 1;
    if (v[i] < 0) {
      k = -1;
    }
    ans = 0;
    i = 0;
    while (i < v.size()) {
      if (k == 1) {
        ma = -1;
        f = 0;
        while (v[i] > 0 && i < v.size()) {
          if (v[i] > ma) {
            ma = v[i];
          }
          f = 1;
          i++;
        }
        k = -1;
        if (f == 1) ans = ans + ma;
      } else {
        f = 0;
        ma = -1000000000000000;
        while (v[i] < 0 && i < v.size()) {
          if (v[i] > ma) {
            ma = v[i];
          }
          f = 1;
          i++;
        }
        k = 1;
        if (f == 1) ans = ans + ma;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
