#include <bits/stdc++.h>
using namespace std;
const double PI = atan(1) * 4;
bool comp(pair<int, int> a, pair<int, int> b) { return b.first < a.first; }
int modpow(int b, int p, int m) {
  if (p == 0) return 1 % m;
  if (p % 2) return (b * modpow(b, p - 1, m)) % m;
  int u = modpow(b, p / 2, m);
  return (u * u) % m;
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    auto p1 = a.begin(), p2 = a.begin();
    long long sum = 0;
    for (int i = 1; i < n; i++) {
      if ((a[i] > 0 && a[i - 1] < 0) || (a[i] < 0 && a[i - 1] > 0)) {
        int mx = (max_element(p1, a.begin() + i) - a.begin());
        p1 = a.begin() + i;
        sum += a[mx];
      }
    }
    if ((*p1 > 0 && *(p1 - 1) < 0) || (*p1 < 0 && *(p1 - 1) > 0)) {
      int mx = (max_element(p1, a.begin() + (n - 1)) - a.begin());
      p1 = a.begin() + n - 1;
      sum += a[mx];
    }
    cout << sum << "\n";
  }
  return 0;
}
