#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool mmax(T &m, const T q) {
  if (m < q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T>
bool mmin(T &m, const T q) {
  if (m > q) {
    m = q;
    return true;
  } else
    return false;
}
const int MOD = 1e9 + 7;
const int MAXN = 2e6 + 3;
const int INF = 1e9;
void solve() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> a(n);
  for (int i = 0; i < (int)(n); ++i) a[i] = (s[i] == '+') ? 1 : -1;
  for (int i = (int)(1); i <= (int)(n - 1); ++i) a[i] += a[i - 1];
  ;
  long long ans = 0;
  int i = 0;
  long long inc = 0;
  while (i < n) {
    while (i < n && (a[i] + inc) >= 0) i++;
    if (i == n) break;
    ans += -(a[i] + inc) * (i + 1);
    inc += -(a[i] + inc);
    i++;
  }
  cout << ans + n << '\n';
}
int main(int argc, char **argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int ntest = 1;
  cin >> ntest;
  while (ntest--) solve();
  return 0;
}
