#include <bits/stdc++.h>
using namespace std;
void fastscan(long long &x) {
  bool neg = false;
  register long long c;
  x = 0;
  c = getchar();
  if (c == '-') {
    neg = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) {
    x = x * 10 + c - 48;
  }
  if (neg) {
    x *= -1;
  }
}
void file() {}
long long bs(long long a[], long long s, long long e, long long x) {
  if (s <= e) {
    long long m = (s + e) / 2;
    if (a[m] == x)
      return m;
    else if (a[m] > x)
      return bs(a, s, m - 1, x);
    else
      return bs(a, m + 1, e, x);
  }
  return -1;
}
bool is_pal(string s) { return equal(begin(s), end(s), s.rbegin()); }
long long mypow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return (res % 1000000007);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  file();
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    ;
    long long a[n];
    for (long long i = 0; i < n; i++) cin >> a[i];
    ;
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      long long curr = a[i];
      long long j = i;
      while (j < n and a[i] * a[j] > 0) {
        curr = max(curr, a[j]);
        j++;
      }
      i = j - 1;
      ans += (curr);
    }
    cout << ans << "\n";
    ;
  }
  return 0;
}
