#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const long long INF = 1e18;
const int N = 1e5 + 5;
bool par(int x, int y) {
  int a = x > 0 ? 1 : 0;
  int b = y > 0 ? 1 : 0;
  return a == b;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    vector<long long> v;
    for (int i = 1; i <= n;) {
      int j = i;
      long long mx = -INF;
      while (j <= n && par(a[i], a[j])) mx = max(mx, a[j]), j++;
      v.push_back(mx);
      i = j;
    }
    long long sum = 0;
    for (auto x : v) sum += x;
    cout << sum << "\n";
  }
  return 0;
}
