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 GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
template <class T>
using vec = std::vector<T>;
bool __hack = std::ios::sync_with_stdio(false);
auto __hack1 = cin.tie(nullptr);
struct Input {
  Input(istream &in) : in(&in) {}
  template <class T>
  T next() const {
    T x;
    *in >> x;
    return x;
  }
  int ni() const { return next<int>(); }
  string ns() const { return next<string>(); }
  istream *in;
};
Input in(cin);
class Output {
 private:
  ostream *out;
  template <typename T>
  void printSingle(const T &value) {
    *out << value;
  }

 public:
  Output(ostream &out) : out(&out) {}
  inline void print() {}
  template <typename T, typename... Ts>
  inline void print(const T &f, const Ts &...args) {
    printSingle(f);
    if (sizeof...(args) != 0) {
      *out << ' ';
      print(args...);
    }
  }
  template <typename... Ts>
  inline void println(const Ts &...args) {
    print(args...);
    *out << '\n';
  }
  template <typename... Ts>
  inline void operator()(const Ts &...args) {
    println(args...);
  }
};
Output out(cout);
namespace template_util {
constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; }
template <int N>
struct bytetype {};
template <uint64_t N>
struct minimal_uint : bytetype<bytecount(N)> {};
}  // namespace template_util
string dir = "WSAD";
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int64_t getResult(const string &s) {
  int x = 0, y = 0;
  int miX = 0, maX = 0;
  int miY = 0, maY = 0;
  for (int i = 0; i < (s.length()); ++i) {
    int d;
    for (d = 0; d < 4; ++d)
      if (dir[d] == s[i]) break;
    x += dx[d];
    y += dy[d];
    if (miX > x) {
      miX = x;
    }
    if (maX < x) {
      maX = x;
    }
    if (miY > y) {
      miY = y;
    }
    if (maY < y) {
      maY = y;
    }
  }
  int64_t h = (maX - miX + 1);
  int64_t w = (maY - miY + 1);
  int64_t res = h * w;
  return res;
}
const int INF = 1000000000;
struct SegmentTreeMin {
  int n;
  vector<int> tmin, tmax;
  vector<int> tadd;
  SegmentTreeMin(int n) : n(n) {
    tmin = vec<int>(4 * n, 0);
    tmax = vec<int>(4 * n, 0);
    tadd = vec<int>(4 * n, 0);
  }
  void combine(int v) {
    tmin[v] = min(tmin[2 * v], tmin[2 * v + 1]);
    tmax[v] = max(tmax[2 * v], tmax[2 * v + 1]);
  }
  void push(int v) {
    if (tadd[v] != 0) {
      if (2 * v < tmin.size()) {
        tmin[2 * v] += tadd[v];
        tmax[2 * v] += tadd[v];
        tadd[2 * v] += tadd[v];
      }
      if (2 * v + 1 < tmin.size()) {
        tmin[2 * v + 1] += tadd[v];
        tmax[2 * v + 1] += tadd[v];
        tadd[2 * v + 1] += tadd[v];
      }
      tadd[v] = 0;
    }
  }
  void update(int pos, int val) {
    int v = 1;
    int le = 0, ri = n;
    while (le + 1 < ri) {
      push(v);
      int m = (le + ri) / 2;
      if (pos < m) {
        ri = m;
        v *= 2;
      } else {
        le = m;
        v = 2 * v + 1;
      }
    }
    tmin[v] = val;
    tmax[v] = val;
    tadd[v] = 0;
    v /= 2;
    while (v) {
      combine(v);
      v /= 2;
    }
  }
  void internalAdd(int l, int r, int v, int vl, int vr, int delta) {
    if (l >= vr || vl >= r) return;
    push(v);
    if (vl >= l && vr <= r) {
      tadd[v] += delta;
      if (tmin[v] != INF) {
        tmin[v] += delta;
        tmax[v] += delta;
      }
      return;
    }
    int vm = (vl + vr) / 2;
    internalAdd(l, r, 2 * v, vl, vm, delta);
    internalAdd(l, r, 2 * v + 1, vm, vr, delta);
    combine(v);
  }
  void updateSuffix(int from, int delta) {
    internalAdd(from, n, 1, 0, n, delta);
  }
  pair<int, int> internalGet(int l, int r, int v, int vl, int vr) {
    if (l >= vr || vl >= r) return {0, 0};
    push(v);
    if (vl >= l && vr <= r) {
      return {tmax[v], tmin[v]};
    }
    int vm = (vl + vr) / 2;
    pair<int, int> p1 = internalGet(l, r, 2 * v, vl, vm);
    pair<int, int> p2 = internalGet(l, r, 2 * v + 1, vm, vr);
    return {max(p1.first, p2.first), min(p1.second, p2.second)};
  }
  pair<int, int> get(int le, int ri) {
    return internalGet(le, ri + 1, 1, 0, n);
  }
};
void solveOne() {
  auto s = in.ns();
  auto res = getResult(s);
  SegmentTreeMin streeX(s.length() + 1), streeY(s.length() + 1);
  int x = 0, y = 0;
  streeX.update(0, x);
  streeY.update(0, y);
  for (int i = 0; i < (s.length()); ++i) {
    int d;
    for (d = 0; d < 4; ++d)
      if (dir[d] == s[i]) break;
    x += dx[d];
    y += dy[d];
    ;
    ;
    streeX.update(i + 1, x);
    streeY.update(i + 1, y);
  }
  for (int i = 0; i < (s.length()); ++i) {
    {
      auto px1 = streeX.get(0, i);
      streeX.updateSuffix(i, 1);
      auto px2 = streeX.get(i, s.length());
      streeX.updateSuffix(i, -1);
      pair<int, int> py = streeY.get(0, s.length());
      pair<int, int> px = {max(px1.first, px2.first),
                           min(px1.second, px2.second)};
      int64_t h = px.first - px.second + 1;
      int64_t w = py.first - py.second + 1;
      res = min(res, h * w);
    }
    {
      auto px1 = streeX.get(0, i);
      streeX.updateSuffix(i, -1);
      auto px2 = streeX.get(i, s.length());
      streeX.updateSuffix(i, 1);
      pair<int, int> py = streeY.get(0, s.length());
      pair<int, int> px = {max(px1.first, px2.first),
                           min(px1.second, px2.second)};
      int64_t h = px.first - px.second + 1;
      int64_t w = py.first - py.second + 1;
      res = min(res, h * w);
    }
    {
      auto py1 = streeY.get(0, i);
      streeY.updateSuffix(i, 1);
      auto py2 = streeY.get(i, s.length());
      streeY.updateSuffix(i, -1);
      pair<int, int> px = streeX.get(0, s.length());
      pair<int, int> py = {max(py1.first, py2.first),
                           min(py1.second, py2.second)};
      int64_t h = px.first - px.second + 1;
      int64_t w = py.first - py.second + 1;
      res = min(res, h * w);
    }
    {
      auto py1 = streeY.get(0, i);
      streeY.updateSuffix(i, -1);
      auto py2 = streeY.get(i, s.length());
      streeY.updateSuffix(i, 1);
      pair<int, int> px = streeX.get(0, s.length());
      pair<int, int> py = {max(py1.first, py2.first),
                           min(py1.second, py2.second)};
      int64_t h = px.first - px.second + 1;
      int64_t w = py.first - py.second + 1;
      res = min(res, h * w);
    }
  }
  res = min(res, getResult("S" + s));
  res = min(res, getResult("W" + s));
  res = min(res, getResult("A" + s));
  res = min(res, getResult("D" + s));
  res = min(res, getResult(s + "S"));
  res = min(res, getResult(s + "W"));
  res = min(res, getResult(s + "A"));
  res = min(res, getResult(s + "D"));
  out(res);
}
void solve(istream &inStream, ostream &outStream) {
  in = Input(inStream);
  out = Output(outStream);
  auto tests = in.ni();
  while (tests--) {
    solveOne();
  }
}
int main() {
  solve(cin, cout);
  return 0;
}
