#include <bits/stdc++.h>
using namespace std;
void cin_ar(int n, int ar[]) {
  for (int i = 0; i < n; i++) cin >> ar[i];
}
void cin_ll(int n, long long ar[]) {
  for (int i = 0; i < n; i++) cin >> ar[i];
}
void cin_v(int n, vector<int> v) {
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
    ;
  }
}
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.first < b.first) return a.first < b.first;
  return a.second < b.second;
}
bool cmp_pair(pair<int, int> A, pair<int, int> B) {
  if (A.first > B.first) return A.first > B.first;
  return A.second > B.second;
}
vector<bool> v(1000006, true);
void print(int n, int ar[]) {
  for (int i = 0; i < n; i++) cout << ar[i] << " ";
  cout << endl;
}
void solve() {
  int n;
  cin >> n;
  long long ar[n];
  int neg = 0;
  long long neg_min = -10000000000000000;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    if (ar[i] < 0) neg++;
    neg_min = max(neg_min, ar[i]);
  }
  long long sum = 0;
  long long t = 0;
  for (int i = 1; i < n; i++) {
    t = ar[i - 1];
    if (ar[i] < 0 && ar[i - 1] < 0 || ar[i] > 0 && ar[i - 1] > 0) {
      t = max(ar[i], ar[i - 1]);
    } else {
      sum += t;
      t = 0;
    }
  }
  sum += t;
  if (neg == n || neg == 0)
    cout << neg_min << endl;
  else
    cout << sum << endl;
}
void solve_2() {
  int t;
  cin >> t;
  while (t--) solve();
}
int main() {
  solve_2();
  return 0;
}
