#include <bits/stdc++.h>
using namespace std;
static const auto speedup = []() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  return 0;
}();
int main() {
  int testcases;
  cin >> testcases;
  for (int testcase = 0; testcase < testcases; testcase++) {
    int n;
    cin >> n;
    long long int sum = 0, m, x;
    bool f;
    cin >> m;
    if (x > 0)
      f = false;
    else
      f = true;
    for (int i = 1; i < n; i++) {
      cin >> x;
      if (x > 0) {
        if (f) {
          sum += m;
          m = x;
          f = false;
        } else
          m = max(m, x);
      } else {
        if (f)
          m = max(m, x);
        else {
          sum += m;
          m = x;
          f = true;
        }
      }
    }
    cout << sum + m << '\n';
  }
  return 0;
}
