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;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << " ";
  err(++it, args...);
}
long long mod(long long x, long long m = 100000007) { return x % m; }
long long power(long long x, long long y, long long p = 100000007) {
  x %= p;
  long long val = 1;
  while (y) {
    if (y & 1LL) val = (val * x) % p;
    y >>= 1LL;
    x = (x * x) % p;
  }
  return val;
}
vector<int> h, v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    h.clear();
    v.clear();
    for (auto it : s) {
      if (it == 'W')
        v.push_back(1);
      else if (it == 'A')
        h.push_back(-1);
      else if (it == 'S')
        v.push_back(-1);
      else
        h.push_back(1);
    }
    long long e[2][2];
    e[0][0] = e[1][0] = 0;
    e[0][1] = e[1][1] = 0;
    long long x = 0;
    for (int i = 0; i < h.size(); i++) {
      x += h[i];
      e[0][0] = min(e[0][0], x);
      e[0][1] = max(e[0][1], x);
    }
    x = 0;
    for (int i = 0; i < v.size(); i++) {
      x += v[i];
      e[1][0] = min(e[1][0], x);
      e[1][1] = max(e[1][1], x);
    }
    long long hl = (e[0][1] - e[0][0] + 1);
    long long vl = (e[1][1] - e[1][0] + 1);
    long long ans = hl * vl;
    x = 0;
    long long h1 = 0, h2 = 0;
    int f = 1;
    long long y1 = -1, y2 = -1;
    for (long long i = 0; i < h.size(); i++) {
      x += h[i];
      if (x == e[0][0]) y1 = i;
      if (x == e[0][1]) y2 = i;
    }
    x = 0;
    for (long long i = -1; i < (long long)h.size(); i++) {
      if (i >= 0) {
        x += h[i];
        h1 = min(h1, x);
        h2 = max(h2, x);
      }
      if (i < (long long)h.size() - 1 && f && i == y1) {
        i++;
        f = 0;
        x += h[i];
        h1 = min(h1, x);
        h2 = max(h2, x);
        x--;
      }
    }
    ans = min(ans, (h2 - h1 + 1) * vl);
    x = 0;
    f = 1;
    h1 = 0;
    h2 = 0;
    for (long long i = -1; i < (long long)h.size(); i++) {
      if (i >= 0) {
        x += h[i];
        h1 = min(h1, x);
        h2 = max(h2, x);
      }
      if (i < (long long)h.size() - 1 && f && i == y2) {
        i++;
        f = 0;
        x += h[i];
        h1 = min(h1, x);
        h2 = max(h2, x);
        x++;
      }
    }
    ans = min(ans, (h2 - h1 + 1) * vl);
    long long v1 = 0, v2 = 0;
    x = 0;
    f = 1;
    y1 = -1;
    y2 = -1;
    for (long long i = 0; i < v.size(); i++) {
      x += v[i];
      if (x == e[1][0]) y1 = i;
      if (x == e[1][1]) y2 = i;
    }
    x = 0;
    for (long long i = -1; i < (long long)v.size(); i++) {
      if (i >= 0) {
        x += v[i];
        v1 = min(v1, x);
        v2 = max(v2, x);
      }
      if (i < (long long)v.size() - 1 && f && i == y1) {
        i++;
        f = 0;
        x += v[i];
        v1 = min(v1, x);
        v2 = max(v2, x);
        x--;
      }
    }
    ans = min(ans, (v2 - v1 + 1) * hl);
    x = 0;
    f = 1;
    v1 = 0;
    v2 = 0;
    for (long long i = -1; i < (long long)v.size(); i++) {
      if (i >= 0) {
        x += v[i];
        v1 = min(v1, x);
        v2 = max(v2, x);
      }
      if (i < (long long)v.size() - 1 && f && i == y2) {
        i++;
        f = 0;
        x += v[i];
        v1 = min(v1, x);
        v2 = max(v2, x);
        x++;
      }
    }
    ans = min(ans, (v2 - v1 + 1) * hl);
    cout << ans << '\n';
  }
}
