#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(15);
  if (argc == 2 && atoi(argv[1]) == 123456789) {
    freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
  }
  int T;
  cin >> T;
  for (int(t) = 0; (t) < (T); (t)++) {
    long long n;
    cin >> n;
    vector<int> a(n);
    for (int(i) = 0; (i) < (n); (i)++) cin >> a[i];
    int mm = -2e9;
    a.push_back(-a.back());
    long long sol = 0;
    for (int(i) = 0; (i) < (n + 1); (i)++) {
      if (i && (a[i] > 0 ^ a[i - 1] > 0)) {
        sol += mm;
        mm = -2e9;
      }
      mm = max(mm, a[i]);
    }
    cout << sol << endl;
  }
  if (argc == 2 && atoi(argv[1]) == 123456789)
    cout << clock() * 1.0 / CLOCKS_PER_SEC << " sec\n";
  return 0;
}
