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 long long INF = 1000000000000000000;
const long long N = 210000;
struct inf {
  long long minx;
  long long maxx;
  long long miny;
  long long maxy;
  long long result() { return (maxx - minx + 1) * (maxy - miny + 1); }
};
inf combine(const inf& inf1, const inf& inf2) {
  return {min(inf1.minx, inf2.minx), max(inf1.maxx, inf2.maxx),
          min(inf1.miny, inf2.miny), max(inf1.maxy, inf2.maxy)};
}
pair<long long, long long> a[N];
inf t[4 * N];
pair<long long, long long> add[4 * N];
void build(long long v, long long l, long long r) {
  if (l == r)
    t[v] = {a[l].first, a[l].first, a[l].second, a[l].second};
  else {
    long long m = (l + r) / 2;
    build(v * 2, l, m);
    build(v * 2 + 1, m + 1, r);
    t[v] = combine(t[v * 2], t[v * 2 + 1]);
  }
}
void push(long long v, long long l, long long r) {
  if (l != r) {
    add[2 * v].first += add[v].first;
    add[2 * v].second += add[v].second;
    add[2 * v + 1].first += add[v].first;
    add[2 * v + 1].second += add[v].second;
  }
  t[v].maxx += add[v].first;
  t[v].maxy += add[v].second;
  t[v].miny += add[v].second;
  t[v].minx += add[v].first;
  add[v] = {0, 0};
}
const inf NullVal = {INF, -INF, INF, -INF};
inf query(long long v, long long tl, long long tr, long long l, long long r) {
  push(v, tl, tr);
  if (l > r) return NullVal;
  if (l == tl && r == tr) return t[v];
  long long m = (tl + tr) / 2;
  return combine(query(v * 2, tl, m, l, min(m, r)),
                 query(v * 2 + 1, m + 1, tr, max(m + 1, l), r));
}
void modify(long long v, long long tl, long long tr, long long l, long long r,
            pair<long long, long long> val) {
  push(v, tl, tr);
  if (l > r) return;
  if (tl == l && tr == r) {
    add[v].first += val.first;
    add[v].second += val.second;
    push(v, tl, tr);
    return;
  }
  long long m = (tl + tr) / 2;
  modify(2 * v, tl, m, l, min(m, r), val);
  modify(2 * v + 1, m + 1, tr, max(m + 1, l), r, val);
  t[v] = combine(t[2 * v], t[2 * v + 1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  for (long long i0 = 0; i0 < t; i0++) {
    string s;
    cin >> s;
    long long x = 0;
    long long y = 0;
    a[0] = {0, 0};
    for (long long i = 0; i < s.length(); i++) {
      if (s[i] == 'W') {
        y++;
      }
      if (s[i] == 'S') {
        y--;
      }
      if (s[i] == 'D') {
        x++;
      }
      if (s[i] == 'A') {
        x--;
      }
      a[i + 1] = {x, y};
    }
    build(1, 0, s.length());
    long long best = query(1, 0, s.length(), 0, s.length()).result();
    for (long long i = 0; i < s.length(); i++) {
      pair<long long, long long> tmp = a[i];
      inf res;
      if (s[i] == 'A') {
        tmp.first++;
        modify(1, 0, s.length(), i + 1, s.length(), {1, 0});
        res = combine(query(1, 0, s.length(), 0, s.length()),
                      {tmp.first, tmp.first, tmp.second, tmp.second});
        modify(1, 0, s.length(), i + 1, s.length(), {-1, 0});
      }
      if (s[i] == 'D') {
        tmp.first--;
        modify(1, 0, s.length(), i + 1, s.length(), {-1, 0});
        res = combine(query(1, 0, s.length(), 0, s.length()),
                      {tmp.first, tmp.first, tmp.second, tmp.second});
        modify(1, 0, s.length(), i + 1, s.length(), {1, 0});
      }
      if (s[i] == 'S') {
        tmp.second++;
        modify(1, 0, s.length(), i + 1, s.length(), {0, 1});
        res = combine(query(1, 0, s.length(), 0, s.length()),
                      {tmp.first, tmp.first, tmp.second, tmp.second});
        modify(1, 0, s.length(), i + 1, s.length(), {0, -1});
      }
      if (s[i] == 'W') {
        tmp.second--;
        modify(1, 0, s.length(), i + 1, s.length(), {0, -1});
        res = combine(query(1, 0, s.length(), 0, s.length()),
                      {tmp.first, tmp.first, tmp.second, tmp.second});
        modify(1, 0, s.length(), i + 1, s.length(), {0, 1});
      }
      best = min(best, res.result());
    }
    cout << best << "\n";
  }
  return 0;
}
