#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) cin >> a[i];
    vector<long long> ans;
    bool neg = true;
    if (a[0] > 0) neg = false;
    long long m1 = a[0];
    for (long long i = 1; i < n; i++) {
      if (a[i] > 0 and neg == false) {
        m1 = max(m1, a[i]);
        if (i == n - 1) ans.push_back(m1);
      } else if (a[i] < 0 and neg == true) {
        m1 = max(m1, a[i]);
        if (i == n - 1) ans.push_back(m1);
      } else {
        ans.push_back(m1);
        m1 = a[i];
        neg = !neg;
        if (i == n - 1) ans.push_back(a[i]);
      }
    }
    long long sum = 0;
    for (long long k = 0; k < ans.size(); k++) sum += ans[k];
    if (sum == 0)
      cout << m1 << "\n";
    else
      cout << sum << "\n";
  }
}
