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;
char s[1000005], t1[1000005], t2[1000005];
int sp[1000005], nrt1, nrt2, ok1, ok2;
long long lat1, lat2;
void f(int &ok1, long long &lat1, int nrt) {
  int i, mini, maxi, poz, poz2;
  mini = 0;
  maxi = 0;
  for (i = 1; i <= nrt; i++) {
    maxi = max(maxi, sp[i]);
    mini = min(mini, sp[i]);
  }
  for (i = 0; i <= nrt; i++)
    if (mini == sp[i]) {
      poz = i;
      break;
    }
  for (i = nrt; i >= 0; i--)
    if (maxi == sp[i]) {
      poz2 = i;
      break;
    }
  if (poz > poz2) ok1 = 1;
  lat1 = maxi - mini + 1;
  for (i = 0; i <= nrt; i++)
    if (maxi == sp[i]) {
      poz = i;
      break;
    }
  for (i = nrt; i >= 0; i--)
    if (mini == sp[i]) {
      poz2 = i;
      break;
    }
  if (poz > poz2) ok1 = 1;
}
int main() {
  int i, nrt;
  cin >> nrt;
  while (nrt--) {
    cin >> s;
    int n = strlen(s);
    nrt1 = 0;
    nrt2 = 0;
    ok1 = 0;
    ok2 = 0;
    for (i = 0; i < n; i++) {
      if ((s[i] == 'S') || (s[i] == 'W')) {
        t1[nrt1] = s[i];
        nrt1++;
      } else {
        t2[nrt2] = s[i];
        nrt2++;
      }
    }
    if (t1[0] == 'S')
      sp[1] = -1;
    else
      sp[1] = 1;
    for (i = 2; i <= nrt1; i++)
      sp[i] = sp[i - 1] + ((t1[i - 1] == 'S') ? -1 : 1);
    f(ok1, lat1, nrt1);
    if (t2[0] == 'A')
      sp[1] = -1;
    else
      sp[1] = 1;
    for (i = 1; i <= nrt2; i++)
      sp[i] = sp[i - 1] + ((t2[i - 1] == 'A') ? -1 : 1);
    f(ok2, lat2, nrt2);
    long long ans = lat1 * lat2;
    if ((ok1) && (lat1 > 2)) ans = min(ans, (lat1 - 1) * lat2);
    if ((ok2) && (lat2 > 2)) ans = min(ans, (lat2 - 1) * lat1);
    cout << ans << "\n";
  }
  return 0;
}
