You have a string s — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands:

  * 'W' — move one cell up; 
  * 'S' — move one cell down; 
  * 'A' — move one cell left; 
  * 'D' — move one cell right. 



Let Grid(s) be the grid of minimum possible area such that there is a position in the grid where you can place the robot in such a way that it will not fall from the grid while running the sequence of commands s. For example, if s = DSAWWAW then Grid(s) is the 4 × 3 grid:

  1. you can place the robot in the cell (3, 2); 
  2. the robot performs the command 'D' and moves to (3, 3); 
  3. the robot performs the command 'S' and moves to (4, 3); 
  4. the robot performs the command 'A' and moves to (4, 2); 
  5. the robot performs the command 'W' and moves to (3, 2); 
  6. the robot performs the command 'W' and moves to (2, 2); 
  7. the robot performs the command 'A' and moves to (2, 1); 
  8. the robot performs the command 'W' and moves to (1, 1). 

<image>

You have 4 extra letters: one 'W', one 'A', one 'S', one 'D'. You'd like to insert at most one of these letters in any position of sequence s to minimize the area of Grid(s).

What is the minimum area of Grid(s) you can achieve?

Input

The first line contains one integer T (1 ≤ T ≤ 1000) — the number of queries.

Next T lines contain queries: one per line. This line contains single string s (1 ≤ |s| ≤ 2 ⋅ 10^5, s_i ∈ \{W, A, S, D\}) — the sequence of commands.

It's guaranteed that the total length of s over all queries doesn't exceed 2 ⋅ 10^5.

Output

Print T integers: one per query. For each query print the minimum area of Grid(s) you can achieve.

Example

Input


3
DSAWWAW
D
WA


Output


8
2
4

Note

In the first query you have to get string DSAWW\underline{D}AW.

In second and third queries you can not decrease the area of Grid(s).
#include <bits/stdc++.h>
using namespace std;
int bst(int a[], int lw, int hi, int n) {
  int mid = (lw + hi) / 2;
  if (lw > hi) return -1;
  if (a[mid] > n)
    bst(a, lw, mid - 1, n);
  else if (a[mid] < n)
    bst(a, mid + 1, hi, n);
  else
    return mid;
}
long long pw(long long a, long long b, long long p) {
  if (b == 0) return 1;
  long long t = pw(a, b / 2, p);
  if (b % 2)
    return (((a * t) % p) * t) % p;
  else
    return ((t * t) % p);
}
void solve() {
  string s;
  long long ct1 = 0, ct2 = 0, V = 0, H = 0;
  cin >> s;
  if (s.size() == 1) {
    cout << 2 << endl;
    return;
  }
  vector<long long> v1, v2;
  v1.push_back(0);
  v2.push_back(0);
  long long i = 0, k = 0, t = 0;
  while (i < s.size()) {
    if (s[i] == 'W') {
      v1.push_back(++ct1);
    } else if (s[i] == 'S') {
      v1.push_back(--ct1);
    } else if (s[i] == 'D') {
      v2.push_back(++ct2);
    } else {
      v2.push_back(--ct2);
    }
    i++;
  }
  if (v1.size() == 2) {
    V = 1;
  }
  if (v2.size() == 2) {
    H = 1;
  }
  long long lw1 = *min_element(v1.begin(), v1.end()),
            hi1 = *max_element(v1.begin(), v1.end());
  long long lw2 = *min_element(v2.begin(), v2.end()),
            hi2 = *max_element(v2.begin(), v2.end());
  vector<long long> min1_pos, min2_pos, max1_pos, max2_pos;
  for (i = 0; i < v1.size(); i++) {
    if (v1[i] == lw1) min1_pos.push_back(i);
    if (v1[i] == hi1) max1_pos.push_back(i);
  }
  for (i = 0; i < v2.size(); i++) {
    if (v2[i] == lw2) min2_pos.push_back(i);
    if (v2[i] == hi2) max2_pos.push_back(i);
  }
  bool v, h;
  long long a, b, c, d;
  a = min1_pos.back();
  b = min1_pos.front();
  c = max1_pos.back();
  d = max1_pos.front();
  if ((c < a && c < b) || (d > a && d > b))
    v = true;
  else
    v = false;
  a = min2_pos.back();
  b = min2_pos.front();
  c = max2_pos.back();
  d = max2_pos.front();
  if ((c < a && c < b) || (d > a && d > b))
    h = true;
  else
    h = false;
  if (V && H) {
    cout << 4 << endl;
  } else if (V) {
    if (h)
      cout << 2 * (hi2 - lw2) << endl;
    else
      cout << 2 * (hi2 - lw2 + 1) << endl;
  } else if (H) {
    if (v)
      cout << 2 * (hi1 - lw1) << endl;
    else
      cout << 2 * (hi1 - lw1 + 1) << endl;
  } else {
    if (v && h)
      cout << min((hi1 - lw1 + 1) * (hi2 - lw2), (hi1 - lw1) * (hi2 - lw2 + 1))
           << endl;
    else if (v)
      cout << (hi1 - lw1) * (hi2 - lw2 + 1) << endl;
    else if (h)
      cout << (hi1 - lw1 + 1) * (hi2 - lw2) << endl;
    else
      cout << (hi1 - lw1 + 1) * (hi2 - lw2 + 1) << endl;
  }
}
int main() {
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
