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;
inline int read();
const int M = 200016, MOD = 1000000007;
char save[M];
int tx[M], ty[M];
int mxy[M], miy[M], mxx[M], mix[M];
int main(void) {
  int T = read();
  while (T--) {
    scanf("%s", save + 1);
    ll x = 0, y = 0;
    tx[0] = ty[0] = 0;
    int n = strlen(save + 1);
    int edx = 0, edy = 0;
    for (int i = 1; i <= n; ++i) {
      if (save[i] == 'W') {
        y++;
        edy = i;
      } else if (save[i] == 'S') {
        y--;
        edy = i;
      } else if (save[i] == 'A') {
        edx = i;
        x--;
      } else {
        edx = i;
        x++;
      }
      tx[i] = x;
      ty[i] = y;
    }
    mxy[n] = miy[n] = ty[n];
    mxx[n] = mix[n] = tx[n];
    for (int i = n - 1; i >= 0; --i) {
      mxy[i] = max(mxy[i + 1], ty[i]);
      mxx[i] = max(mxx[i + 1], tx[i]);
      miy[i] = min(miy[i + 1], ty[i]);
      mix[i] = min(mix[i + 1], tx[i]);
    }
    int cand = 0, cana = 0, canw = 0, cans = 0;
    for (int i = 0; i < edx; ++i) {
      if (mxx[i] != mxx[0]) cand = 1;
      if (tx[i] == mix[0]) break;
    }
    for (int i = 0; i < edx; ++i) {
      if (mix[i] != mix[0]) cana = 1;
      if (tx[i] == mxx[0]) break;
    }
    for (int i = 0; i < edy; ++i) {
      if (mxy[i] != mxy[0]) canw = 1;
      if (ty[i] == miy[0]) break;
    }
    for (int i = 0; i < edy; ++i) {
      if (miy[i] != miy[0]) cans = 1;
      if (ty[i] == mxy[0]) break;
    }
    int canx = cana | cand, cany = canw | cans;
    ll xlen = mxx[0] - mix[0] + 1, ylen = mxy[0] - miy[0] + 1;
    ll ans = xlen * ylen;
    ll sub = 0;
    if (canx) sub = max(sub, ylen);
    if (cany) sub = max(sub, xlen);
    ans -= sub;
    cout << ans << endl;
  }
  return 0;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
