#include <bits/stdc++.h>
using namespace std;
char s[200005], t[200005];
int n, w, h, u, d, l, r, x, y, pu, pd, pl, pr;
void insert(int pos, char ch) {
  int len = strlen(t + 1);
  for (int i = len; i >= pos; i--) t[i + 1] = t[i];
  t[pos] = ch;
}
void calc() {
  int len = strlen(t + 1), u = 0, d = 0, l = 0, r = 0, x = 0, y = 0;
  for (int i = 1; i <= len; i++) {
    if (t[i] == 'W') y++;
    if (t[i] == 'S') y--;
    if (t[i] == 'A') x--;
    if (t[i] == 'D') x++;
    if (y > u) u = y;
    if (y < d) d = y;
    if (x > r) r = x;
    if (x < l) l = x;
  }
  w = r - l + 1;
  h = u - d + 1;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    u = 0, d = 0, l = 0, r = 0, x = 0, y = 0;
    pu = pd = pl = pr = 0;
    memset(s, 0, sizeof s);
    scanf("%s", s + 1);
    n = strlen(s + 1);
    for (int i = 1; i <= n; i++) {
      if (s[i] == 'W') y++;
      if (s[i] == 'S') y--;
      if (s[i] == 'A') x--;
      if (s[i] == 'D') x++;
      if (y > u) u = y, pu = i;
      if (y < d) d = y, pd = i;
      if (x > r) r = x, pr = i;
      if (x < l) l = x, pl = i;
    }
    w = r - l + 1;
    h = u - d + 1;
    long long ans = (long long)w * h;
    memset(t, 0, sizeof t);
    memcpy(t, s, sizeof s);
    if (pu) insert(pu, 'S');
    calc();
    ans = min(ans, 1ll * w * h);
    memset(t, 0, sizeof t);
    memcpy(t, s, sizeof s);
    if (pd) insert(pd, 'W');
    calc();
    ans = min(ans, 1ll * w * h);
    memset(t, 0, sizeof t);
    memcpy(t, s, sizeof s);
    if (pr) insert(pr, 'A');
    calc();
    ans = min(ans, 1ll * w * h);
    memset(t, 0, sizeof t);
    memcpy(t, s, sizeof s);
    if (pl) insert(pl, 'D');
    calc();
    ans = min(ans, 1ll * w * h);
    cout << ans << '\n';
  }
}
