#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  while (a != 0) {
    T temp = a;
    a = b % a;
    b = temp;
  }
  return b;
}
template <class T>
T egcd(T a, T b, T &x, T &y) {
  T gcd, xt, yt;
  if (a == 0) {
    gcd = b;
    x = 0, y = 1;
  } else {
    gcd = egcd(b % a, a, xt, yt);
    x = yt - (b / a) * xt;
    y = xt;
  }
  return gcd;
}
template <class T>
T expo(T base, T exp, T mod) {
  T res = 1;
  base = base % mod;
  while (exp > 0) {
    if (exp & 1) res = (res * base) % mod;
    exp = exp >> 1;
    base = (base * base) % mod;
  }
  return res;
}
template <class T>
T modinv(T a, T mod) {
  T x, y;
  egcd<T>(a, mod, x, y);
  while (x < 0) x += mod;
  while (x >= mod) x -= mod;
  return x;
}
template <class T>
T modinvfermat(T a, T mod) {
  return expo<T>(a, mod - 2, mod);
}
template <class T>
bool rev(T a, T b) {
  return a > b;
}
template <class T>
long long maxpower(T a, T b) {
  long long ans = 0;
  while (a > 0 && a % b == 0) {
    ans++;
    a /= b;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; i++) cin >> a[i];
    vector<long long> p, N;
    long long cnt = 0;
    for (long long i = 0; i < n; i++) {
      long long maxp = 0, maxn = -9999999999999;
      if (cnt % 2 == 0) {
        cnt++;
        while (i < n && a[i] < 0) i++;
        while (i < n && a[i] > 0) {
          maxp = max(maxp, a[i]);
          i++;
        }
        i--;
        if (maxp != 0) p.push_back(maxp);
      } else {
        cnt++;
        while (i < n && a[i] > 0) i++;
        while (i < n && a[i] < 0) {
          maxn = max(maxn, a[i]);
          i++;
        }
        i--;
        if (maxn != -9999999999999) p.push_back(maxn);
      }
    }
    cnt = 0;
    for (long long i = 0; i < n; i++) {
      long long maxp = 0, maxn = -9999999999999;
      if (cnt % 2 == 1) {
        cnt++;
        while (i < n && a[i] < 0) i++;
        while (i < n && a[i] > 0) {
          maxp = max(maxp, a[i]);
          i++;
        }
        i--;
        if (maxp != 0) N.push_back(maxp);
      } else {
        cnt++;
        while (i < n && a[i] > 0) i++;
        while (i < n && a[i] < 0) {
          maxn = max(maxn, a[i]);
          i++;
        }
        i--;
        if (maxn != -9999999999999) N.push_back(maxn);
      }
    }
    long long sum = 0, sum2 = 0;
    for (long long i = 0; i < p.size(); i++) {
      sum += p[i];
    }
    for (long long i = 0; i < N.size(); i++) {
      sum2 += N[i];
    }
    if (sum == 0)
      cout << sum2 << endl;
    else if (sum2 == 0)
      cout << sum << endl;
    else if (N.size() > p.size())
      cout << sum2 << endl;
    else if (N.size() < p.size())
      cout << sum << endl;
    else
      cout << max(sum, sum2) << endl;
  }
}
