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 maxn = 1e6 * 2;
inline int g() {
  int x;
  cin >> x;
  return x;
}
inline long long gl() {
  long long x;
  cin >> x;
  return x;
}
inline char gc() {
  char x;
  cin >> x;
  return x;
}
inline string gs() {
  string s;
  cin >> s;
  return s;
}
template <typename T>
inline vector<T> gv(int len) {
  vector<T> a(len);
  for (auto &it : a) cin >> it;
  return a;
}
inline vector<int> gv(int len) {
  vector<int> a(len);
  for (auto &it : a) cin >> it;
  return a;
}
inline vector<pair<int, int>> gv_andPairCnt(int len) {
  vector<pair<int, int>> a(len);
  int i = 1;
  for (auto &it : a) {
    it.second = i;
    i++;
    cin >> it.first;
  }
  return a;
}
double power_log(double power, double val) { return log(val) / log(power); }
template <typename T>
T sqr(T x) {
  return x * x;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto it : v) os << it << " ";
  os << "\n";
  return os;
}
template <typename T, typename H>
inline vector<pair<T, H>> gv_andBiPair(int len) {
  vector<pair<T, H>> a(len);
  for (auto &it : a) {
    cin >> it.first >> it.second;
  }
  return a;
}
template <typename T>
inline set<T> vector_to_set(const vector<T> &vec) {
  set<T> s;
  for (auto &it : vec) s.insert(it);
  return s;
}
const long long md = 1e9 + 7;
void minr(int &x, int mn) { x = min(x, mn); }
bool isOne(int x, int pos) { return ((1 << pos) & x) > 0; }
struct pos {
  int l = 0, r = 0;
  void upd(int x) {
    l = min(x, l);
    r = max(x, r);
  }
};
int main() {
  int T = g();
  for (int T1 = 0; T1 < (T); ++T1) {
    string s = gs();
    vector<int> d1, d2;
    d1.push_back(0);
    d2.push_back(0);
    for (auto it : s) {
      if (it == 'W') {
        d1.push_back(-1);
      }
      if (it == 'S') {
        d1.push_back(1);
      }
      if (it == 'A') {
        d2.push_back(-1);
      }
      if (it == 'D') {
        d2.push_back(1);
      }
    }
    auto ok = [](vector<int> v) {
      if (v.empty()) {
        return 0;
      }
      vector<int> pref = v;
      for (int i = 1; i < pref.size(); i++) {
        pref[i] += pref[i - 1];
      }
      int mx = *max_element(pref.begin(), pref.end());
      int mn = *min_element(pref.begin(), pref.end());
      int pos = ((int)pref.size() - 1) -
                (find(pref.rbegin(), pref.rend(), mx) - pref.rbegin());
      int pos_mn = (find(pref.begin(), pref.end(), mn) - pref.begin());
      assert(pos >= 0);
      assert(pos < pref.size());
      assert(pos_mn >= 0);
      assert(pos_mn < pref.size());
      if (pos_mn > pos) {
        return 1;
      }
      return 0;
    };
    auto multi = [](vector<int> v) {
      for (auto &it : v) {
        it *= -1;
      }
      return v;
    };
    auto get_pref = [](vector<int> v) {
      for (int i = 1; i < v.size(); i++) {
        v[i] += v[i - 1];
      }
      return v;
    };
    int ok1 = ok(d1) || ok(multi(d1));
    int ok2 = ok(d2) || ok(multi(d2));
    auto p1 = get_pref(d1);
    auto p2 = get_pref(d2);
    auto minmax1 = minmax_element(p1.begin(), p1.end());
    int diff1 = abs(*minmax1.first - *minmax1.second) + 1;
    auto minmax2 = minmax_element(p2.begin(), p2.end());
    int diff2 = abs(*minmax2.first - *minmax2.second) + 1;
    long long ans1 = 1LL * (diff1 == 1 ? 1 : max(2, diff1 - ok1)) * diff2;
    long long ans2 = 1LL * diff1 * (diff2 == 1 ? 1 : max(2, diff2 - ok2));
    cout << min(ans1, ans2) << '\n';
  }
}
