#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  cin >> TESTS;
  while (TESTS--) {
    long long n;
    cin >> n;
    vector<long long> arr;
    long long x;
    cin >> x;
    arr.push_back(x);
    for (long long i = 1; i < n; i++) {
      cin >> x;
      long long k = arr.size() - 1;
      if (x * arr[k] < 0)
        arr.push_back(x);
      else
        arr[k] = max(arr[k], x);
    }
    long long sum = 0;
    for (auto j : arr) sum += j;
    cout << sum << endl;
  }
  return 0;
}
