#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (auto &x : a) cin >> x;
    long long cur = a[0];
    auto ptr = a.begin();
    ptr++;
    int sign;
    if (cur > 0)
      sign = 1;
    else
      sign = -1;
    long long tot = 0;
    while (ptr != a.end()) {
      if ((*ptr) * sign > 0)
        cur = max(*ptr, cur);
      else {
        tot += cur;
        cur = *ptr;
        if (sign == 1)
          sign = -1;
        else
          sign = 1;
      }
      ptr++;
    }
    tot += cur;
    cout << tot << "\n";
  }
  return 0;
}
