#include <bits/stdc++.h>
using namespace std;
long long a[200005];
long long t, n, dem1, dem2, s1, s2, i;
bool kt1, kt2;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t != 0) {
    cin >> n;
    s1 = 0;
    s2 = 0;
    kt1 = false;
    kt2 = false;
    for (i = 1; i <= n; i++) cin >> a[i];
    for (i = 1; i <= n; i++) {
      if (kt1 == false) {
        if (a[i] > 0) {
          s1 += a[i];
          dem1++;
          kt1 = true;
        }
      } else {
        if (a[i] < 0) {
          s1 += a[i];
          dem1++;
          kt1 = false;
        }
      }
      if (kt2 == false) {
        if (a[i] < 0) {
          dem2++;
          s2 += a[i];
          kt2 = true;
        }
      } else {
        if (a[i] > 0) {
          dem2++;
          s2 += a[i];
          kt2 = false;
        }
      }
    }
    if (dem1 > dem2)
      cout << s1 << "\n";
    else
      cout << s2 << "\n";
    t--;
  }
}
