#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, 1, -1, 0};
long long mo = 1e9;
const long double P = 3.141592653589793238L;
void trust_yourself() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long gcd(long long x, long long y) {
  if (x == 0) return y;
  return gcd(y % x, x);
}
long long fast_power(long long x, long long y, long long mo) {
  long long p = 1;
  while (y) {
    if (y & 1) p = (p * x) % mo;
    y = (y >> 1);
    x = (x * x) % mo;
  }
  return p;
}
long long convert_to_num(string x) {
  long long num = 0;
  for (int i = 0; i < x.size(); i++) {
    num *= 2;
    num += x[i] - '0';
  }
  return num;
}
long long com(long long n, long long r) {
  long long p = 1, p1 = 1;
  for (long long i = r + 1; i <= n; i++) {
    p = p * i;
    p /= p1;
    p1++;
  }
  return p;
}
int main() {
  trust_yourself();
  int t;
  cin >> t;
  while (t--) {
    int n, a[200009], m = 0, x = 0, y = 0, m1 = INT_MIN, c = 0, c1 = 0,
                      mx = INT_MIN;
    long long s = 0, s1 = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      mx = max(a[i], mx);
    }
    for (int i = 0; i < n; i++) {
      if (a[i] > 0 && x == 0) {
        m = max(m, a[i]);
        y = 1;
      } else if (a[i] < 0 && y == 1) {
        m1 = max(m1, a[i]);
        x = 1;
      } else {
        if (x == 1 && y == 1) {
          s += m + m1;
          c += 2;
          i--;
        }
        x = 0, y = 0;
        m = 0, m1 = INT_MIN;
      }
    }
    if (x == 1 && y == 1) {
      s += m + m1;
      c += 2;
    }
    x = 0, y = 0, m = 0, m1 = INT_MIN;
    for (int i = 0; i < n; i++) {
      if (a[i] < 0 && x == 0) {
        m1 = max(m1, a[i]);
        y = 1;
      } else if (a[i] > 0 && y == 1) {
        m = max(m, a[i]);
        x = 1;
      } else {
        if (x == 1 && y == 1) {
          s1 += m + m1;
          c1 += 2;
          i--;
        }
        x = 0, y = 0;
        m = 0, m1 = INT_MIN;
      }
    }
    if (x == 1 && y == 1) {
      s1 += m + m1;
      c1 += 2;
    }
    if (c == c1 && c != 0)
      cout << max(s, s1) << '\n';
    else if (c > c1)
      cout << s << '\n';
    else if (c1 > c)
      cout << s1 << '\n';
    else
      cout << mx << '\n';
  }
  return 0;
}
