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;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
const char dir[] = {'R', 'L', 'D', 'U'};
ll add(ll a, ll b) {
  a += b;
  if (a >= MOD) {
    a -= MOD;
  }
  return a;
}
int sub(int a, int b) {
  a -= b;
  if (a < 0) a += MOD;
  return a;
}
int mult(int a, int b) { return ((ll)a * b) % MOD; }
void setIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
int main() {
  setIO();
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    vector<int> ns, ew;
    int n = s.length();
    for (int i = 0; i < n; ++i) {
      if (s[i] == 'W')
        ns.emplace_back(1);
      else if (s[i] == 'S')
        ns.emplace_back(-1);
      else if (s[i] == 'D')
        ew.emplace_back(1);
      else
        ew.emplace_back(-1);
    }
    int d1 = 1e9, d2 = 1e9;
    int origd1 = 1, origd2 = 1;
    int sz = 0;
    vector<int> cur;
    cur = ns;
    sz = ns.size();
    if (sz) {
      int pmx[sz], smx[sz], pmn[sz], smn[sz];
      int vals[sz];
      for (int i = 0; i < sz; ++i) {
        vals[i] = cur[i];
        if (i) vals[i] += vals[i - 1];
      }
      for (int i = 0; i < sz; ++i) {
        pmx[i] = max(0, vals[i]);
        pmn[i] = min(0, vals[i]);
        if (i) {
          pmx[i] = max(pmx[i], pmx[i - 1]);
          pmn[i] = min(pmn[i], pmn[i - 1]);
        }
      }
      for (int i = sz - 1; i >= 0; --i) {
        smx[i] = vals[i];
        smn[i] = vals[i];
        if (i < sz - 1) {
          smx[i] = max(smx[i], smx[i + 1]);
          smn[i] = min(smn[i], smn[i + 1]);
        }
      }
      d1 = pmx[ns.size() - 1] - pmn[ns.size() - 1] + 1;
      origd1 = d1;
      for (int i = 0; i < ns.size() - 1; ++i) {
        int curn = max(pmx[i], smx[i + 1] + 1);
        int curs = min(pmn[i], smn[i + 1] + 1);
        d1 = min(d1, curn - curs + 1);
        curn = max(pmx[i], smx[i + 1] - 1);
        curs = min(pmn[i], smn[i + 1] - 1);
        d1 = min(d1, curn - curs + 1);
      }
    }
    cur = ew;
    sz = ew.size();
    if (sz) {
      int pmx2[sz], smx2[sz], pmn2[sz], smn2[sz];
      int vals2[sz];
      for (int i = 0; i < sz; ++i) {
        vals2[i] = cur[i];
        if (i) vals2[i] += vals2[i - 1];
      }
      for (int i = 0; i < sz; ++i) {
        pmx2[i] = max(0, vals2[i]);
        pmn2[i] = min(0, vals2[i]);
        if (i) {
          pmx2[i] = max(pmx2[i], pmx2[i - 1]);
          pmn2[i] = min(pmn2[i], pmn2[i - 1]);
        }
      }
      for (int i = sz - 1; i >= 0; --i) {
        smx2[i] = vals2[i];
        smn2[i] = vals2[i];
        if (i < sz - 1) {
          smx2[i] = max(smx2[i], smx2[i + 1]);
          smn2[i] = min(smn2[i], smn2[i + 1]);
        }
      }
      d2 = pmx2[ew.size() - 1] - pmn2[ew.size() - 1] + 1;
      origd2 = d2;
      for (int i = 0; i < ew.size() - 1; ++i) {
        int cure = max(pmx2[i], smx2[i + 1] + 1);
        int curw = min(pmn2[i], smn2[i + 1] + 1);
        d2 = min(d2, cure - curw + 1);
        cure = max(pmx2[i], smx2[i + 1] - 1);
        curw = min(pmn2[i], smn2[i + 1] - 1);
        d2 = min(d2, cure - curw + 1);
      }
    }
    if (d1 == 1e9) d1 = 1;
    if (d2 == 1e9) d2 = 1;
    cout << min((ll)d1 * origd2, (ll)origd1 * d2) << "\n";
  }
}
