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 comment(linker, "/STACK:102400000,102400000")
using std::cin;
using std::cout;
using std::string;
using LL = long long;
using db = double;
using pii = std::pair<int, int>;
using vi = std::vector<int>;
const int MAXN = 2e5 + 10;
struct SegTree {
  const int INF = 1e9;
  struct Node {
    int l, r, max, min;
    friend Node operator+(Node x, Node y) {
      if (x.l == -1) return y;
      if (y.l == -1) return x;
      Node res;
      res.l = x.l;
      res.r = y.r;
      res.max = std::max(y.max, x.max);
      res.min = std::min(y.min, x.min);
      return res;
    }
  };
  int M;
  Node T[MAXN * 4];
  void init(int n) {
    for (M = 1; M < n + 10; M <<= 1)
      ;
    for (int i = 0; i < M; ++i) T[M + i] = {i, i, 0, INF};
    for (int i = M - 1; i; --i) T[i] = T[i + i] + T[i + i + 1];
  }
  void modify(int n, int val) {
    T[n + M] = {n, n, val, val};
    for (n += M, n >>= 1; n; n >>= 1) T[n] = T[n + n] + T[n + n + 1];
  }
  Node get(int l, int r, int v = 1) {
    if (T[v].l >= l && T[v].r <= r) return T[v];
    if (T[v].l > r || T[v].r < l) return (Node){-1, -1, 0, INF};
    return get(l, r, v + v) + get(l, r, v + v + 1);
  }
} TX, TY;
std::map<char, int> X, Y;
void solve() {
  string s;
  cin >> s;
  int n = s.length();
  TX.init(n + 10), TY.init(n + 10);
  int x = n + 1, y = n + 1;
  TX.modify(1, x), TY.modify(1, y);
  for (int i = 0; i < n; ++i) {
    x += X[s[i]], y += Y[s[i]];
    TX.modify(i + 2, x), TY.modify(i + 2, y);
  }
  SegTree::Node xr = TX.get(1, n + 1), yr = TY.get(1, n + 1);
  int dx = xr.max - xr.min + 1, dy = yr.max - yr.min + 1;
  LL ans = (LL)dx * dy;
  for (int i = 2; i < n + 2; ++i) {
    int ax = std::max(TX.get(1, i).max, TX.get(i + 1, n + 1).max - X[s[i - 2]]);
    int bx = std::min(TX.get(1, i).min, TX.get(i + 1, n + 1).min - X[s[i - 2]]);
    int ay = std::max(TY.get(1, i).max, TY.get(i + 1, n + 1).max - Y[s[i - 2]]);
    int by = std::min(TY.get(1, i).min, TY.get(i + 1, n + 1).min - Y[s[i - 2]]);
    ans = std::min(ans, (LL)(ax - bx + 1) * (ay - by + 1));
  }
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  X['W'] = 1, X['S'] = -1, X['A'] = X['D'] = 0;
  Y['D'] = 1, Y['A'] = -1, Y['W'] = Y['S'] = 0;
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
