#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long power(long long num, long long r) {
  if (r == 0) return 1;
  if (r == 1) return num % mod;
  long long ans = power(num, r / 2) % mod;
  if (r % 2 == 0) {
    return (ans * ans) % mod;
  }
  return (((ans * ans) % mod) * num) % mod;
}
long long modinv(long long num) { return power(num, mod - 2); }
int findset(int arr[], int x) {
  if (x != arr[x]) {
    arr[x] = findset(arr, arr[x]);
  }
  return arr[x];
}
void uni(int arr[], int ranks[], int a, int b) {
  int ra = findset(arr, a);
  int rb = findset(arr, b);
  if (ra != rb) {
    if (ranks[ra] < ranks[rb]) swap(ra, rb);
    arr[rb] = ra;
    if (ranks[ra] == ranks[rb]) {
      ranks[ra]++;
    }
  }
}
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 arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    long long sum = 0;
    long long mx = arr[0];
    int par = -1;
    if (arr[0] > 0) par = 1;
    for (int i = 1; i < n; i++) {
      if (arr[i] > 0) {
        if (par == 1) {
          mx = max(mx, arr[i]);
        } else {
          sum += mx;
          mx = arr[i];
          par = 1;
        }
      } else {
        if (par == 1) {
          sum += mx;
          mx = arr[i];
          par = -1;
        } else {
          mx = max(mx, arr[i]);
        }
      }
    }
    sum += mx;
    cout << sum << "\n";
  }
  return 0;
}
