#include <bits/stdc++.h>
using namespace std;
long long gcdEx(long long a, long long b, long long* x, long long* y) {
  if (!a) {
    *x = 0;
    *y = 1;
    return b;
  }
  long long x1, y1, gcd = gcdEx(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long modI(long long b, long long m) {
  long long x, y;
  gcdEx(b, m, &x, &y);
  return (x % m + m) % m;
}
long long modP(long long x, long long y) {
  long long r = 1;
  x %= 1000000007;
  while (y > 0) {
    if (y & 1) {
      r = (r * x) % 1000000007;
    }
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return r;
}
long long max(long long a, long long b) { return (a > b ? a : b); }
long long min(long long a, long long b) { return (a < b ? a : b); }
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, (a % b));
  }
}
long long lcm(long long a, long long b) {
  long long ans = (a / gcd(a, b)) * b;
  return ans;
}
void solve() {
  long long ans = 0;
  string s;
  cin >> s;
  long long cur = 0;
  long long n = s.size();
  ans += n;
  long long min_neg = 0;
  long long cnt = 0;
  map<int, int> check;
  for (char ch : s) {
    cnt++;
    if (ch == '+')
      cur++;
    else
      cur--;
    if (cur < 0) {
      if (check[cur] == 1) continue;
      ans += (cnt);
      check[cur] = 1;
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
