#include <bits/stdc++.h>
using namespace std;
long long exp(long long a, long long n) {
  if (n == 0) return 1;
  if (n == 1) return a;
  if (n % 2) {
    long long s = exp(a, n - 1);
    return s * a;
  } else {
    long long s = exp(a, n / 2);
    return s * s;
  }
}
long long max(long long a, long long b) { return a > b ? a : b; }
void solve() {
  string str;
  cin >> str;
  int n = str.length();
  int net = 0;
  int ma = 0;
  int cur = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == '-')
      net--;
    else
      net++;
    ma = min(ma, net);
  }
  if (ma == 0) {
    cout << n << "\n";
    return;
  }
  vector<int> dp(n, 0);
  dp[0] = str[0] == '+' ? 1 : -1;
  map<int, int> ans_key;
  int smallest = 0;
  for (int i = 0; i < n; i++) {
    if (i > 0 && str[i] == '+')
      dp[i] = dp[i - 1] + 1;
    else if (i > 0)
      dp[i] = dp[i - 1] - 1;
    smallest = min(smallest, dp[i]);
    if (dp[i] <= smallest && dp[i] != ma) {
      ans_key[dp[i]] = i + 2;
    }
  }
  long long ans = 0;
  if (str[0] == '-') ans += 1;
  for (int i = ma + 1; i <= 0; i++) {
    ans += ans_key[i];
  }
  cout << ans + n << "\n";
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
