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;
const int N = 2e5 + 10;
const int INF = 1e9;
char s[N];
int a[2][N];
int premin[N], premax[N], sufmin[N], sufmax[N];
int calc(int x, int id, int d) {
  int recmin = min(premin[x - 1], sufmin[x] + d);
  recmin = min(recmin, a[id][x - 1] + d);
  int recmax = max(premax[x - 1], sufmax[x] + d);
  recmax = max(recmax, a[id][x - 1] + d);
  return recmax - recmin + 1;
}
int main() {
  int T;
  scanf("%d", &T);
  int n, cnt1, cnt2, ans, rec1, rec2, flag1, flag2;
  long long anss;
  while (T--) {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    cnt1 = cnt2 = 0;
    for (int i = 1; i <= n; i++) {
      if (s[i] == 'A') {
        a[0][cnt1 + 1] = a[0][cnt1] - 1;
        cnt1++;
      } else if (s[i] == 'D') {
        a[0][cnt1 + 1] = a[0][cnt1] + 1;
        cnt1++;
      } else if (s[i] == 'S') {
        a[1][cnt2 + 1] = a[1][cnt2] - 1;
        cnt2++;
      } else {
        a[1][cnt2 + 1] = a[1][cnt2] + 1;
        cnt2++;
      }
    }
    premin[0] = premax[0] = 0;
    sufmin[cnt1 + 1] = INF;
    sufmax[cnt1 + 1] = -INF;
    for (int i = 1; i <= cnt1; i++) {
      premin[i] = min(premin[i - 1], a[0][i]);
      premax[i] = max(premax[i - 1], a[0][i]);
    }
    for (int i = cnt1; i >= 1; i--) {
      sufmin[i] = min(sufmin[i + 1], a[0][i]);
      sufmax[i] = max(sufmax[i + 1], a[0][i]);
    }
    rec1 = premax[cnt1] - premin[cnt1] + 1;
    ans = INF;
    for (int i = 1; i <= cnt1; i++) {
      ans = min(ans, calc(i, 0, -1));
      ans = min(ans, calc(i, 0, 1));
    }
    if (ans < rec1)
      flag1 = 1;
    else
      flag1 = 0;
    premin[0] = premax[0] = 0;
    sufmin[cnt2 + 1] = INF;
    sufmax[cnt2 + 1] = -INF;
    for (int i = 1; i <= cnt2; i++) {
      premin[i] = min(premin[i - 1], a[1][i]);
      premax[i] = max(premax[i - 1], a[1][i]);
    }
    for (int i = cnt2; i >= 1; i--) {
      sufmin[i] = min(sufmin[i + 1], a[1][i]);
      sufmax[i] = max(sufmax[i + 1], a[1][i]);
    }
    rec2 = premax[cnt2] - premin[cnt2] + 1;
    ans = INF;
    for (int i = 1; i <= cnt2; i++) {
      ans = min(ans, calc(i, 1, -1));
      ans = min(ans, calc(i, 1, 1));
    }
    if (ans < rec2)
      flag2 = 1;
    else
      flag2 = 0;
    anss = 1LL * rec1 * rec2;
    if (flag1) anss = min(anss, 1LL * (rec1 - 1) * rec2);
    if (flag2) anss = min(anss, 1LL * rec1 * (rec2 - 1));
    printf("%I64d\n", anss);
  }
  return 0;
}
