#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long int invmod(long long int x, long long int n, long long int mod) {
  if (n == 0) return 1 % mod;
  long long int half = invmod(x, n / 2, mod);
  half = (half * half) % mod;
  if (n % 2 == 1) half = (half * (x % mod)) % mod;
  return half;
}
long long int bin(long long int a[], long long int l, long long int r,
                  long long int x) {
  if (l <= r) {
    long long int m = l + (r - l) / 2;
    if (a[m] == x)
      return m;
    else if (a[m] > x)
      return bin(a, l, m - 1, x);
    else
      return bin(a, m + 1, r, x);
  } else
    return -1;
}
long long int power(long long int b, long long int e, long long int m) {
  if (e == 0) return 1;
  if (e % 2)
    return b * power(b * b % m, (e - 1) / 2, m) % m;
  else
    return power(b * b % m, e / 2, m);
}
long long int power(long long int b, long long int e) {
  if (e == 0) return 1;
  if (e % 2)
    return b * power(b * b, (e - 1) / 2);
  else
    return power(b * b, e / 2);
}
long long int ncr(long long int n, long long int r, long long int x) {
  if (r == 0) return 1;
  long long int fac[n + 1];
  fac[0] = 1;
  for (long long int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % x;
  return (fac[n] * power(fac[r], x - 2, x) % x * power(fac[n - r], x - 2, x) %
          x) %
         x;
}
long long int ncr(long long int n, long long int p) {
  long long int r = min(p, n - p), rf = 1, ln = 1;
  for (long long int i = 1; i <= r; i++) rf = rf * i;
  for (long long int i = 0; i < r; i++) ln = ln * (n - i);
  return ln / rf;
}
bool sbs(pair<long long int, long long int> &a,
         pair<long long int, long long int> &b) {
  return (a.second < b.second);
}
bool sbds(pair<long long int, long long int> &a,
          pair<long long int, long long int> &b) {
  return (a.second > b.second);
}
bool sdf(pair<long long int, long long int> &a,
         pair<long long int, long long int> &b) {
  return (a.first > b.first);
}
long long int SUM(long long int a[], long long int n) {
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) sum += a[i];
  return sum;
}
long long int chkprm(long long int n) {
  long long int x = 5, s = sqrt(n);
  if (n < 2) return 0;
  if (n < 4) return 1;
  if ((n & 1) == 0) return 0;
  if (n % 3 == 0) return 0;
  while (x <= s) {
    if (n % x == 0) return 0;
    x += 2;
    if (n % x == 0) return 0;
    x += 4;
  }
  return 1;
}
void myth() {
  string s;
  cin >> s;
  long long int cnt = 0, ans = 0, chk = -1;
  for (long long int i = 0; i < s.length(); i++) {
    if (s[i] == '+')
      cnt++;
    else
      cnt--;
    if (cnt == chk) {
      chk--;
      ans += (i + 1);
    }
  }
  cout << ans + s.length();
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int test_case = 1;
  cin >> test_case;
  while (test_case--) {
    myth();
    cout << "\n";
  }
  cerr << "\n"
       << "Time Elasped : " << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
  return 0;
}

### Prompt

In CPP, your task is to solve the following problem:

You are given a string s consisting only of characters + and -. You perform some process with this string. This process can be described by the following pseudocode: 
    
    
    res = 0  
    for init = 0 to inf  
        cur = init  
        ok = true  
        for i = 1 to |s|  
            res = res + 1  
            if s[i] == '+'  
                cur = cur + 1  
            else  
                cur = cur - 1  
            if cur < 0  
                ok = false  
                break  
        if ok  
            break  
    

Note that the inf denotes infinity, and the characters of the string are numbered from 1 to |s|.

You have to calculate the value of the res after the process ends.

Input

The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases.

The only lines of each test case contains string s (1 ≤ |s| ≤ 10^6) consisting only of characters + and -.

It's guaranteed that sum of |s| over all test cases doesn't exceed 10^6.

Output

For each test case print one integer — the value of the res after the process ends.

Example

Input


3
--+-
---
++--+-


Output


7
9
6

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long int invmod(long long int x, long long int n, long long int mod) {
  if (n == 0) return 1 % mod;
  long long int half = invmod(x, n / 2, mod);
  half = (half * half) % mod;
  if (n % 2 == 1) half = (half * (x % mod)) % mod;
  return half;
}
long long int bin(long long int a[], long long int l, long long int r,
                  long long int x) {
  if (l <= r) {
    long long int m = l + (r - l) / 2;
    if (a[m] == x)
      return m;
    else if (a[m] > x)
      return bin(a, l, m - 1, x);
    else
      return bin(a, m + 1, r, x);
  } else
    return -1;
}
long long int power(long long int b, long long int e, long long int m) {
  if (e == 0) return 1;
  if (e % 2)
    return b * power(b * b % m, (e - 1) / 2, m) % m;
  else
    return power(b * b % m, e / 2, m);
}
long long int power(long long int b, long long int e) {
  if (e == 0) return 1;
  if (e % 2)
    return b * power(b * b, (e - 1) / 2);
  else
    return power(b * b, e / 2);
}
long long int ncr(long long int n, long long int r, long long int x) {
  if (r == 0) return 1;
  long long int fac[n + 1];
  fac[0] = 1;
  for (long long int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % x;
  return (fac[n] * power(fac[r], x - 2, x) % x * power(fac[n - r], x - 2, x) %
          x) %
         x;
}
long long int ncr(long long int n, long long int p) {
  long long int r = min(p, n - p), rf = 1, ln = 1;
  for (long long int i = 1; i <= r; i++) rf = rf * i;
  for (long long int i = 0; i < r; i++) ln = ln * (n - i);
  return ln / rf;
}
bool sbs(pair<long long int, long long int> &a,
         pair<long long int, long long int> &b) {
  return (a.second < b.second);
}
bool sbds(pair<long long int, long long int> &a,
          pair<long long int, long long int> &b) {
  return (a.second > b.second);
}
bool sdf(pair<long long int, long long int> &a,
         pair<long long int, long long int> &b) {
  return (a.first > b.first);
}
long long int SUM(long long int a[], long long int n) {
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) sum += a[i];
  return sum;
}
long long int chkprm(long long int n) {
  long long int x = 5, s = sqrt(n);
  if (n < 2) return 0;
  if (n < 4) return 1;
  if ((n & 1) == 0) return 0;
  if (n % 3 == 0) return 0;
  while (x <= s) {
    if (n % x == 0) return 0;
    x += 2;
    if (n % x == 0) return 0;
    x += 4;
  }
  return 1;
}
void myth() {
  string s;
  cin >> s;
  long long int cnt = 0, ans = 0, chk = -1;
  for (long long int i = 0; i < s.length(); i++) {
    if (s[i] == '+')
      cnt++;
    else
      cnt--;
    if (cnt == chk) {
      chk--;
      ans += (i + 1);
    }
  }
  cout << ans + s.length();
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int test_case = 1;
  cin >> test_case;
  while (test_case--) {
    myth();
    cout << "\n";
  }
  cerr << "\n"
       << "Time Elasped : " << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
  return 0;
}

```