#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
const double inf = 1000;
const long long mod = 1000;
long long _pow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a;
    a = a * a;
    b >>= 1;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
long long a[maxn];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    for (long long i = 1; i <= n; i++) {
      cin >> a[i];
    }
    long long flag = -1, flag1 = -1e10, flag2 = 0, sum = 0;
    for (long long i = 1; i <= n; i++) {
      if (a[i] < 0) {
        if (flag2 > 0) flag = 1;
        if (flag == 1) {
          flag = -2;
          sum += flag2;
        }
        flag2 = 0;
        flag1 = max(flag1, a[i]);
      }
      if (a[i] > 0) {
        if (flag1 > -1e10) flag = 0;
        if (flag == 0) {
          flag = -3;
          sum += flag1;
        }
        flag1 = -1e10;
        flag2 = max(flag2, a[i]);
      }
    }
    if (flag == -3) sum += flag2;
    if (flag == -2) sum += flag1;
    if (flag == -1) {
      if (a[1] > 0)
        sum += flag2;
      else
        sum += flag1;
    }
    if (flag == 0) sum += flag2;
    if (flag == 1) sum += flag1;
    cout << sum << endl;
  }
  return 0;
}
