#include <bits/stdc++.h>
using namespace std;
int t;
char a[200010];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%s", a);
    int le = 0, ri = 0, up = 0, dw = 0, len = strlen(a), x = 0, y = 0;
    int fle = 0, fri = 0, fup = 0, fdw = 0;
    for (int i = 0; i < len; i++) {
      if (a[i] == 'W') {
        if (++y > up)
          up = y, fdw = 0, fup = 1;
        else if (y == up)
          fup = 1;
      }
      if (a[i] == 'A') {
        if (--x < le)
          le = x, fri = 0, fle = 1;
        else if (x == le)
          fle = 1;
      }
      if (a[i] == 'S') {
        if (--y < dw)
          dw = y, fup = 0, fdw = 1;
        else if (y == dw)
          fdw = 1;
      }
      if (a[i] == 'D') {
        if (++x > ri)
          ri = x, fle = 0, fri = 1;
        else if (x == ri)
          fri = 1;
      }
    }
    x = ri - le + 1, y = up - dw + 1;
    long long s = 1LL * x * y, k = s;
    if (x > 2 && fle * fri == 0) s = k - y;
    if (y > 2 && fup * fdw == 0 && k - x < s) s = k - x;
    printf("%lld\n", s);
  }
}
