#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long temp;
  while (1) {
    if (b % a == 0) return a;
    temp = a;
    a = b % a;
    b = temp;
  }
}
int main() {
  long long n, m, p, q, c, i, x, j, t, k, sum = 0, cnt = 0, ans, res;
  cin >> q;
  while (q--) {
    vector<long long> v, vv;
    cin >> n;
    long long a[n];
    cnt = 0;
    sum = 0;
    c = 0;
    for (i = 0; i < n; i++) cin >> a[i];
    i = 0;
    while (i < n) {
      if (a[i] > 0) {
        sum = 0;
        while (1) {
          if (a[i] < 0) break;
          sum = max(sum, a[i]);
          i++;
        }
        cnt += sum;
      } else {
        sum = a[i];
        while (1) {
          if (a[i] > 0) break;
          sum = max(sum, a[i]);
          i++;
        }
        cnt += sum;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
