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>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long MOD = 1000000007;
double eps = 1e-12;
const int N = 2e5 + 7;
int n;
string str;
map<char, int> mp1;
long long ans = 2e18;
void solve() {
  mp1.clear();
  cin >> str;
  ans = 2e18;
  n = ((long long)(str).size());
  mp1['W'] = 1;
  mp1['S'] = -1;
  mp1['A'] = -1;
  mp1['D'] = 1;
  int cr = 0, cc = 0;
  vector<int> vechor, vecver;
  vecver.push_back(0);
  vechor.push_back(0);
  int mnr = 0, mxr = 0, mnc = 0, mxc = 0;
  for (long long i = 0; i <= n - 1; i++) {
    if (str[i] == 'W' or str[i] == 'S') {
      cc += mp1[str[i]];
      vecver.push_back(cc);
      mnc = min(mnc, cc);
      mxc = max(mxc, cc);
    } else {
      cr += mp1[str[i]];
      vechor.push_back(cr);
      mnr = min(mnr, cr);
      mxr = max(mxr, cr);
    }
  }
  ans = min(ans, (long long)(mxr - mnr + 1) * (mxc - mnc + 1));
  vector<int> tmp;
  int pos = -1;
  for (long long i = ((long long)(vecver).size()) - 1; i >= 0; i--) {
    if (vecver[i] == mxc) {
      pos = i;
      break;
    }
  }
  tmp = vecver;
  for (long long i = pos + 2; i <= ((long long)(tmp).size()) - 1; i++)
    tmp[i] += 1;
  int tmpmnc = N;
  for (long long i = 0; i <= ((long long)(tmp).size()) - 1; i++)
    tmpmnc = min(tmpmnc, tmp[i]);
  ans = min(ans, (long long)(mxr - mnr + 1) * (mxc - tmpmnc + 1));
  pos = -1;
  for (long long i = ((long long)(vecver).size()) - 1; i >= 0; i--) {
    if (vecver[i] == mnc) {
      pos = i;
      break;
    }
  }
  tmp.clear();
  tmp = vecver;
  for (long long i = pos + 2; i <= ((long long)(tmp).size()) - 1; i++)
    tmp[i] -= 1;
  int tmpmxc = -1;
  for (long long i = 0; i <= ((long long)(tmp).size()) - 1; i++)
    tmpmxc = max(tmpmxc, tmp[i]);
  ans = min(ans, (long long)(mxr - mnr + 1) * (tmpmxc - mnc + 1));
  pos = -1;
  for (long long i = ((long long)(vechor).size()) - 1; i >= 0; i--) {
    if (vechor[i] == mnr) {
      pos = i;
      break;
    }
  }
  tmp.clear();
  tmp = vechor;
  for (long long i = pos + 2; i <= ((long long)(tmp).size()) - 1; i++)
    tmp[i] -= 1;
  int tmpmxr = -1;
  for (long long i = 0; i <= ((long long)(tmp).size()) - 1; i++)
    tmpmxr = max(tmpmxr, tmp[i]);
  ans = min(ans, (long long)(tmpmxr - mnr + 1) * (mxc - mnc + 1));
  pos = -1;
  for (long long i = ((long long)(vechor).size()) - 1; i >= 0; i--) {
    if (vechor[i] == mxr) {
      pos = i;
      break;
    }
  }
  tmp.clear();
  tmp = vechor;
  for (long long i = pos + 2; i <= ((long long)(tmp).size()) - 1; i++)
    tmp[i] += 1;
  int tmpmnr = N;
  for (long long i = 0; i <= ((long long)(tmp).size()) - 1; i++)
    tmpmnr = min(tmpmnr, tmp[i]);
  ans = min(ans, (long long)(mxr - tmpmnr + 1) * (mxc - mnc + 1));
  cout << ans << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  for (int it = 1; it <= t; it++) {
    solve();
  }
  return 0;
}
