#include <bits/stdc++.h>
using namespace std;
long long int MOD = 998244353;
double eps = 1e-12;
long long int gcd(long long int a, long long int b) {
  if (b > a) {
    return gcd(b, a);
  }
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long int expo(long long int a, long long int b, long long int mod) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b = b >> 1;
  }
  return res;
}
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    long long int sum = 0;
    long long int maxp = INT_MIN;
    long long int maxn = INT_MIN;
    multiset<long long int> pos;
    multiset<long long int> neg;
    long long int x = 0;
    while (x < n) {
      if (arr[x] < 0) {
        while (arr[x] < 0) {
          maxn = max(maxn, arr[x]);
          x++;
        }
        while (arr[x] > 0) {
          maxp = max(maxp, arr[x]);
          x++;
        }
        if (maxp != INT_MIN and maxn != INT_MIN) {
          sum += maxn + maxp;
        } else {
          sum += maxn;
        }
        maxp = INT_MIN;
        maxn = INT_MIN;
      } else {
        while (arr[x] > 0) {
          maxp = max(maxp, arr[x]);
          x++;
        }
        while (arr[x] < 0) {
          maxn = max(maxn, arr[x]);
          x++;
        }
        if (maxn != INT_MIN and maxp != INT_MIN) {
          sum += maxn + maxp;
        } else {
          sum += maxp;
        }
        maxp = INT_MIN;
        maxn = INT_MIN;
      }
    }
    cout << sum << endl;
  }
}
