#include <bits/stdc++.h>
using namespace std;
map<char, int> v;
vector<int> v1;
set<int> myset;
set<char> myst;
int n, m, i, j, k, l, r, ans = 0, cnt = 0, tt;
int x = 0, y, a, b, t;
string st, str;
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    int a[n];
    for (i = 0; i < n; i++) cin >> a[i];
    ;
    int sum = 0;
    for (i = 0; i < n;) {
      int maxi;
      if (a[i] < 0) {
        maxi = a[i];
        while (i < n && a[i] < 0) {
          maxi = max(a[i], maxi);
          i++;
        }
      } else {
        maxi = a[i];
        while (i < n && a[i] > 0) {
          maxi = max(a[i], maxi);
          i++;
        }
      }
      sum += maxi;
    }
    cout << sum << endl;
    ;
  }
}
