#include <bits/stdc++.h>
using namespace std;
bool sortin(const pair<long long int, long long int> &e,
            const pair<long long int, long long int> &f) {
  return (e.first < f.first);
}
long long int i, j, k, l, m, n, c, p, q, ts, mn = 10e17, mod = 10e8 + 7;
long long int a[250002], b[250002], x[250002];
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  };
  cin >> ts;
  while (ts--) {
    cin >> n;
    for (long long int i = 0; i <= n - 1; i++) cin >> a[i];
    c = 0;
    p = 0;
    q = -1e18;
    for (long long int i = 0; i <= n - 1; i++) {
      if (a[i] > 0) {
        p = max(p, a[i]);
        if (a[i + 1] < 0 || i == n - 1) {
          c = c + p;
          p = 0;
        }
      } else {
        q = max(q, a[i]);
        if (a[i + 1] > 0 || i == n - 1) {
          c = c + q;
          q = -1e18;
        }
      }
    }
    cout << c;
    cout << endl;
  }
}
