#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
  if (a < b) return a;
  return b;
}
bool comp(long long a, long long b) { return a > b; }
int main(int argc, char const *argv[]) {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<long long> neg;
    vector<long long> pos;
    int cur = a[0];
    long long sum = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] < 0 && cur < 0) {
        if (cur < a[i]) cur = a[i];
      } else if (a[i] > 0 && cur > 0) {
        if (cur < a[i]) cur = a[i];
      } else {
        if (cur < 0)
          neg.push_back(cur);
        else
          pos.push_back(cur);
        sum += cur;
        cur = a[i];
      }
    }
    sum += cur;
    cout << sum << endl;
  }
  return 0;
}
