#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
char s[N];
int pre[N], h[N];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", s + 1);
    memset(pre, 0, sizeof(pre));
    memset(h, 0, sizeof(h));
    int x, y, l, r, u, d;
    x = y = l = r = u = d = 0;
    int len = strlen(s + 1);
    for (int i = 1; i <= len; i++) {
      if (s[i] == 'W')
        y++;
      else if (s[i] == 'S')
        y--;
      else if (s[i] == 'A')
        x--;
      else
        x++;
      l = min(l, x), r = max(r, x), u = max(u, y), d = min(d, y);
    }
    long long ans = 1ll * (r - l + 1) * (u - d + 1);
    string a, b;
    for (int i = 1; i <= len; i++)
      if (s[i] == 'W' || s[i] == 'S')
        a += s[i];
      else
        b += s[i];
    int la = a.length(), lb = b.length();
    for (int i = 1; i <= la; i++)
      if (a[i - 1] == 'W')
        pre[i] = pre[i - 1] + 1;
      else
        pre[i] = pre[i - 1] - 1;
    for (int i = 1; i <= lb; i++)
      if (b[i - 1] == 'D')
        h[i] = h[i - 1] + 1;
      else
        h[i] = h[i - 1] - 1;
    int pl1 = 0, pl2 = 0, pr1 = 0, pr2 = 0;
    int mi = 0, ma = 0;
    for (int i = 1; i <= la; i++)
      if (pre[i] > ma) {
        ma = pre[i];
        pl1 = i;
      }
    for (int i = la; i >= 1; i--)
      if (pre[i] == ma) {
        pr1 = i;
        break;
      }
    for (int i = 1; i <= la; i++)
      if (pre[i] < mi) {
        mi = pre[i];
        pl2 = i;
      }
    for (int i = la; i >= 1; i--)
      if (pre[i] == mi) {
        pr2 = i;
        break;
      }
    if (pr2 < pl1 && la > 1 || pl2 > pr1 && la > 1)
      ans = min(ans, (u - d) * 1ll * (r - l + 1));
    pl1 = pl2 = pr1 = pr2 = 0;
    mi = 0, ma = 0;
    for (int i = 1; i <= lb; i++)
      if (h[i] > ma) {
        ma = h[i];
        pl1 = i;
      }
    for (int i = lb; i >= 1; i--)
      if (h[i] == ma) {
        pr1 = i;
        break;
      }
    for (int i = 1; i <= lb; i++)
      if (h[i] < mi) {
        mi = h[i];
        pl2 = i;
      }
    for (int i = lb; i >= 1; i--)
      if (h[i] == mi) {
        pr2 = i;
        break;
      }
    if (pr2 < pl1 && lb > 1 || pl2 > pr1 && lb > 1)
      ans = min(ans, (u - d + 1) * 1ll * (r - l));
    printf("%lld\n", ans);
  }
  return 0;
}
