#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long a;
  cin >> a;
  while (a--) {
    long long n;
    cin >> n;
    vector<long long> v(n);
    for (long long i = 0; i < n; i++) cin >> v[i];
    long long t = v[0], k = -1000000000000000000, flag = 0,
              k1 = -1000000000000000000, ans = 0;
    if (v[0] < 0 && v[1] > 0) k1 = v[0];
    if (v[0] > 0 && v[1] < 0) k = v[0];
    for (long long i = 1; i < n; i++) {
      if (v[i] > 0 && v[i - 1] > 0) {
        k = max(k, v[i]);
        flag = 1;
      } else if (v[i] < 0 && v[i - 1] < 0) {
        k1 = max(k1, v[i]);
        flag = 2;
      } else if (v[i] > 0 & v[i - 1] < 0) {
        ans += k1;
        k = v[i];
        k1 = 1000000000000000000;
      } else if (v[i] < 0 && v[i - 1] > 0) {
        ans += k;
        k1 = v[i];
        k = -1000000000000000000;
      }
    }
    if (k1 != 1000000000000000000) ans += k1;
    if (k != -1000000000000000000) ans += k;
    cout << ans << '\n';
  }
  return 0;
}
