#include <bits/stdc++.h>
using namespace std;
void DSUinit(vector<long long int>& a, vector<long long int>& size,
             long long int n) {
  for (long long int i = 0; i < n; i++) {
    a[i] = i;
    size[i] = 1;
  }
  return;
}
long long int root(vector<long long int>& a, long long int i) {
  return (i == a[i]) ? i : a[i] = root(a, a[i]);
}
bool DSUfind(vector<long long int> a, long long int x, long long int y) {
  if (root(a, x) == root(a, y)) {
    return true;
  }
  return false;
}
void DSUunion(vector<long long int>& a, vector<long long int>& size,
              long long int x, long long int y) {
  x = root(a, x);
  y = root(a, y);
  if (x == y) {
    return;
  }
  if (size[x] < size[y]) swap(x, y);
  a[y] = x;
  size[x] += size[y];
}
void dfs(vector<vector<long long int> >& graph, vector<bool>& visited,
         long long int start) {
  visited[start] = true;
  for (long long int i = 0; i < graph[start].size(); i++) {
    if (!(visited[graph[start][i]])) {
      dfs(graph, visited, graph[start][i]);
    }
  }
  return;
}
bool isPrime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long int power(long long int x, long long int y, long long int p) {
  long long int ans = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y) {
    if (y & 1) ans = (ans * x) % p;
    y >>= 1;
    x = (x * x) % p;
  }
  return ans;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long int c0 = 0;
    long long int c1 = 0;
    long long int n = s.size();
    long long int cur = 0;
    vector<long long int> v0(n, 0);
    vector<long long int> v1(n, 0);
    vector<long long int> val(n, 0);
    for (long long int i = 0; i < n; i++) {
      if (s[i] == '+') {
        c1 += 1;
        cur += 1;
        val[i] = cur;
      } else {
        c0 += 1;
        cur -= 1;
        val[i] = cur;
      }
      v0[i] = c0;
      v1[i] = c1;
    }
    long long int mi = 0;
    long long int ans = 0;
    for (long long int i = 0; i < n; i++) {
      if (mi > val[i]) {
        mi = val[i];
        ans += (i + 1);
      }
    }
    ans += n;
    cout << ans << "\n";
  }
  return 0;
}

### Prompt

Your task is to create a Cpp solution to 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>
using namespace std;
void DSUinit(vector<long long int>& a, vector<long long int>& size,
             long long int n) {
  for (long long int i = 0; i < n; i++) {
    a[i] = i;
    size[i] = 1;
  }
  return;
}
long long int root(vector<long long int>& a, long long int i) {
  return (i == a[i]) ? i : a[i] = root(a, a[i]);
}
bool DSUfind(vector<long long int> a, long long int x, long long int y) {
  if (root(a, x) == root(a, y)) {
    return true;
  }
  return false;
}
void DSUunion(vector<long long int>& a, vector<long long int>& size,
              long long int x, long long int y) {
  x = root(a, x);
  y = root(a, y);
  if (x == y) {
    return;
  }
  if (size[x] < size[y]) swap(x, y);
  a[y] = x;
  size[x] += size[y];
}
void dfs(vector<vector<long long int> >& graph, vector<bool>& visited,
         long long int start) {
  visited[start] = true;
  for (long long int i = 0; i < graph[start].size(); i++) {
    if (!(visited[graph[start][i]])) {
      dfs(graph, visited, graph[start][i]);
    }
  }
  return;
}
bool isPrime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long int power(long long int x, long long int y, long long int p) {
  long long int ans = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y) {
    if (y & 1) ans = (ans * x) % p;
    y >>= 1;
    x = (x * x) % p;
  }
  return ans;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long int c0 = 0;
    long long int c1 = 0;
    long long int n = s.size();
    long long int cur = 0;
    vector<long long int> v0(n, 0);
    vector<long long int> v1(n, 0);
    vector<long long int> val(n, 0);
    for (long long int i = 0; i < n; i++) {
      if (s[i] == '+') {
        c1 += 1;
        cur += 1;
        val[i] = cur;
      } else {
        c0 += 1;
        cur -= 1;
        val[i] = cur;
      }
      v0[i] = c0;
      v1[i] = c1;
    }
    long long int mi = 0;
    long long int ans = 0;
    for (long long int i = 0; i < n; i++) {
      if (mi > val[i]) {
        mi = val[i];
        ans += (i + 1);
      }
    }
    ans += n;
    cout << ans << "\n";
  }
  return 0;
}

```