#include <bits/stdc++.h>
using namespace std;
double pi = acos(-1);
long long i, j;
long long n, m, fb[100];
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
double C(long long n, long long m) {
  if (m < 0 || m > n) return 0;
  double ans = 1;
  for (double i = 1; i <= m; i++) ans = ans * (n - m + i) / i;
  return ans;
}
long long binaryPow(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = ans * a;
    }
    a = a * a;
    b >>= 1;
  }
  return ans;
}
void exgcd(int a, int b, int &d, int &x, int &y) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    exgcd(b, a % b, d, y, x);
    y -= x * (a / b);
  }
}
long long c[300][300];
long long a[300];
void C() {
  memset(c, 0, sizeof(c));
  for (int i = 0; i < 220; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % 1000000007;
    }
  }
}
void dp() {
  c[0][1] = c[1][1] = c[2][1] = c[2][2] = c[3][1] = c[3][3] = 1;
  a[1] = 1, a[2] = a[3] = 2;
  for (int i = 4; i <= 250; i++) {
    long long t = 0;
    for (int j = 1; j <= i / 2; j++) {
      if (j == 1)
        c[i][1] = a[i - 2];
      else {
        long long q = i - 2 * j;
        if (q == 0)
          c[i][j] = 1;
        else {
          long long s = 0;
          for (int p = j; p <= q; p++) s += c[q][p];
          c[i][j] = s;
        }
      }
      t += c[i][j];
    }
    c[i][i] = 1;
    a[i] = t + 1;
  }
}
int h[1000010];
char ch[1000010];
void gg() {
  memset(h, 0, sizeof(h));
  long long n, ans = 0, dy, xy, v = 0;
  scanf("%s", ch);
  dy = strlen(ch);
  for (int i = 0; i <= dy; i++) {
    if (ch[i] == '+')
      h[i + 1] = h[i] + 1;
    else
      h[i + 1] = h[i] - 1;
  }
  for (i = 1; i <= dy; i++) {
    if (v + h[i] < 0) ans += i, v++;
  }
  cout << ans + dy << '\n';
}
int main() {
  dp();
  int t;
  cin >> t;
  while (t--) gg();
}
