#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    vector<long long> ans;
    long long n;
    cin >> n;
    long long ara[n];
    for (long long i = 0; i < n; i++) {
      cin >> ara[i];
    }
    vector<long long> v;
    v.push_back(ara[0]);
    for (long long i = 1; i < n; i++) {
      if (ara[i] > 0 && ara[i - 1] > 0) {
        v.push_back(ara[i]);
      } else if (ara[i] < 0 && ara[i - 1] < 0) {
        v.push_back(ara[i]);
      } else {
        if (v[0] > 0) {
          sort(v.begin(), v.end());
          ans.push_back(v.back());
          v.clear();
          v.push_back(ara[i]);
        } else {
          sort(v.begin(), v.end());
          ans.push_back(v.back());
          v.clear();
          v.push_back(ara[i]);
        }
      }
    }
    if (v.size()) {
      if (v[0] > 0) {
        sort(v.begin(), v.end());
        ans.push_back(v.back());
      } else {
        sort(v.begin(), v.end());
        ans.push_back(v.back());
      }
    }
    long long ok = 0;
    for (long long i = 0; i < ans.size(); i++) {
      ok += ans[i];
    }
    cout << ok << endl;
  }
}
