#include <bits/stdc++.h>
using namespace std;
int len = 0;
long long int ans = LONG_MIN;
pair<int, long long int> solve(vector<vector<pair<int, long long int>>>& v,
                               int index, vector<int>& arr, int pos) {
  if (index >= arr.size()) {
    return {0, LONG_MIN};
  }
  if (v[index][pos].first != -1) {
    return v[index][pos];
  }
  pair<int, long long int> inc;
  if (arr[index] > 0 && pos) {
    pair<int, long long int> a = solve(v, index + 1, arr, 0);
    if (a.second == LONG_MIN) {
      inc.first = 1;
      inc.second = arr[index];
    } else {
      inc.first = a.first + 1;
      inc.second = a.second + arr[index];
    }
  } else if (arr[index] < 0 && !pos) {
    pair<int, long long int> a = solve(v, index + 1, arr, 1);
    if (a.second == LONG_MIN) {
      inc.first = 1;
      inc.second = arr[index];
    } else {
      inc.first = a.first + 1;
      inc.second = a.second + arr[index];
    }
  }
  pair<int, int> ex = solve(v, index + 1, arr, pos);
  if (inc.first > ex.first ||
      (inc.first == ex.first && inc.second >= ex.second)) {
    v[index][pos] = inc;
  } else {
    v[index][pos] = ex;
  }
  if (v[index][pos].first > len) {
    len = v[index][pos].first;
    ans = v[index][pos].second;
  }
  if (v[index][pos].first == len) {
    ans = max(ans, v[index][pos].second);
  }
  return v[index][pos];
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    len = 0;
    ans = LONG_MIN;
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    vector<vector<pair<int, long long int>>> v(
        n, vector<pair<int, long long int>>(2, {-1, -1}));
    solve(v, 0, arr, 0);
    solve(v, 0, arr, 1);
    cout << ans << endl;
  }
  return 0;
}
