#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int main() {
  long long n;
  cin >> n;
  while (n--) {
    long long a;
    cin >> a;
    vector<long long> v(a);
    for (long long i = 0; i < a; i++) cin >> v[i];
    long long s = 0, ans = -1000000000000000000, flag = 0, flag1 = 0,
              ans1 = -1000000000000000000, i = 0;
    while (i < a) {
      while (v[i] > 0) {
        ans = max(ans, v[i]);
        flag = 1;
        i++;
        if (i == a) break;
      }
      if (flag == 1) {
        s += ans;
        flag = 0;
        ans = -1000000000000000000;
      }
      while (v[i] < 0) {
        ans1 = max(ans1, v[i]);
        i++;
        flag1 = 1;
        if (i == a) break;
      }
      if (flag1 == 1) {
        s += ans1;
        flag1 = 0;
        ans1 = -1000000000000000000;
      }
      if (i == a) break;
    }
    cout << s << '\n';
  }
}
