#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, a;
    cin >> n;
    vector<long long> v, v1;
    for (int i = 0; i < n; i++) {
      cin >> a;
      v.push_back(a);
    }
    int flag;
    long long mx = v[0];
    if (v[0] > 0)
      flag = 1;
    else
      flag = 0;
    for (int i = 0; i < n; i++) {
      if (flag == 1 && v[i] > 0) {
        mx = max(v[i], mx);
      } else if (flag == 1 && v[i] < 0) {
        v1.push_back(mx);
        mx = v[i];
        flag = 0;
      } else if (flag == 0 && v[i] < 0) {
        mx = max(v[i], mx);
      } else if (flag == 0 && v[i] > 0) {
        v1.push_back(mx);
        mx = v[i];
        flag = 1;
      }
    }
    v1.push_back(mx);
    long long sum = 0;
    for (int i = 0; i < v1.size(); i++) {
      sum += v1[i];
    }
    cout << sum << endl;
  }
  return 0;
}
