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 = 2e5 + 5;
struct info {
  int minValue, maxValue;
};
info operator+(info A, info B) {
  info output;
  output.minValue = min(A.minValue, B.minValue);
  output.maxValue = max(A.maxValue, B.maxValue);
  return output;
}
struct node {
  int lazy;
  info value;
  int l, r;
  node *L, *R;
  node() {}
  node(int l, int r) {
    this->lazy = 0;
    this->value = {MAXN, -MAXN};
    this->l = l;
    this->r = r;
    this->L = nullptr;
    this->R = nullptr;
  }
  void updateLazy() {
    this->value.maxValue += this->lazy;
    this->value.minValue += this->lazy;
    if (this->l != this->r) {
      this->L->lazy += this->lazy;
      this->R->lazy += this->lazy;
    }
    this->lazy = 0;
  }
  void build() {
    if (this->l == this->r) {
      return;
    }
    this->L = new node(this->l, (this->l + this->r) / 2);
    this->R = new node((this->l + this->r) / 2 + 1, this->r);
    this->L->build();
    this->R->build();
  }
  void update(int q, int val) {
    this->updateLazy();
    if (this->l == this->r && this->l == q) {
      this->value = {val, val};
      return;
    }
    if (this->r < q || this->l > q) return;
    this->L->update(q, val);
    this->R->update(q, val);
    this->value = this->L->value + this->R->value;
  }
  void reset(int q) {
    this->updateLazy();
    if (this->l == this->r && this->l == q) {
      this->value = {MAXN, -MAXN};
      return;
    }
    if (this->r < q || this->l > q) return;
    this->L->reset(q);
    this->R->reset(q);
    this->value = this->L->value + this->R->value;
  }
  void update(int ql, int qr, int val) {
    this->updateLazy();
    if (this->l >= ql && this->r <= qr) {
      this->value.minValue += val;
      this->value.maxValue += val;
      if (this->l != this->r) {
        this->L->lazy += val;
        this->R->lazy += val;
      }
      return;
    }
    if (this->r < ql || this->l > qr) return;
    this->L->update(ql, qr, val);
    this->R->update(ql, qr, val);
    this->value = this->L->value + this->R->value;
  }
};
node *T1, *T2;
int prefix1[MAXN], prefix2[MAXN];
long long calcValue(int sum1, int sum2) {
  long long side1 = 1;
  if (min(sum1, T1->value.minValue) < 0) side1 -= min(sum1, T1->value.minValue);
  if (max(sum1, T1->value.maxValue) > 0) side1 += max(sum1, T1->value.maxValue);
  long long side2 = 1;
  if (min(sum2, T2->value.minValue) < 0) side2 -= min(sum2, T2->value.minValue);
  if (max(sum2, T2->value.maxValue) > 0) side2 += max(sum2, T2->value.maxValue);
  return side1 * side2;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    string s;
    cin >> s;
    T1 = new node(0, s.size());
    T1->build();
    T2 = new node(0, s.size());
    T2->build();
    int sum1 = 0, sum2 = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'W')
        sum1--;
      else if (s[i] == 'S')
        sum1++;
      if (s[i] == 'A')
        sum2--;
      else if (s[i] == 'D')
        sum2++;
      T1->update(i, sum1);
      T2->update(i, sum2);
    }
    long long answer = calcValue(sum1, sum2);
    int currSum1 = 0, currSum2 = 0;
    for (int i = 0; i < s.size(); i++) {
      T1->update(i, s.size() - 1, -1);
      currSum1--;
      answer = min(answer, calcValue(currSum1, currSum2));
      T1->update(i, s.size() - 1, +1);
      currSum1++;
      if (s[i] == 'W')
        currSum1--;
      else if (s[i] == 'S')
        currSum1++;
      if (s[i] == 'A')
        currSum2--;
      else if (s[i] == 'D')
        currSum2++;
    }
    T1->update(s.size(), sum1 - 1);
    answer = min(answer, calcValue(sum1 - 1, sum2));
    T1->reset(s.size());
    currSum1 = 0, currSum2 = 0;
    for (int i = 0; i < s.size(); i++) {
      T1->update(i, s.size() - 1, +1);
      currSum1++;
      answer = min(answer, calcValue(currSum1, currSum2));
      T1->update(i, s.size() - 1, -1);
      currSum1--;
      if (s[i] == 'W')
        currSum1--;
      else if (s[i] == 'S')
        currSum1++;
      if (s[i] == 'A')
        currSum2--;
      else if (s[i] == 'D')
        currSum2++;
    }
    T1->update(s.size(), sum1 + 1);
    answer = min(answer, calcValue(sum1 + 1, sum2));
    T1->reset(s.size());
    currSum1 = 0, currSum2 = 0;
    for (int i = 0; i < s.size(); i++) {
      T2->update(i, s.size() - 1, -1);
      currSum2--;
      answer = min(answer, calcValue(currSum1, currSum2));
      T2->update(i, s.size() - 1, +1);
      currSum2++;
      if (s[i] == 'W')
        currSum1--;
      else if (s[i] == 'S')
        currSum1++;
      if (s[i] == 'A')
        currSum2--;
      else if (s[i] == 'D')
        currSum2++;
    }
    T2->update(s.size(), sum2 - 1);
    answer = min(answer, calcValue(sum1, sum2 - 1));
    T2->reset(s.size());
    currSum1 = 0, currSum2 = 0;
    for (int i = 0; i < s.size(); i++) {
      T2->update(i, s.size() - 1, +1);
      currSum2++;
      answer = min(answer, calcValue(currSum1, currSum2));
      T2->update(i, s.size() - 1, -1);
      currSum2--;
      if (s[i] == 'W')
        currSum1--;
      else if (s[i] == 'S')
        currSum1++;
      if (s[i] == 'A')
        currSum2--;
      else if (s[i] == 'D')
        currSum2++;
    }
    T2->update(s.size(), sum2 + 1);
    answer = min(answer, calcValue(sum1, sum2 + 1));
    T2->reset(s.size());
    cout << answer << '\n';
  }
}
