#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000005;
const int mod = 998244353;
char s[maxn];
long long maxlast, maxfirst, minlast, minfirst;
long long solve(char a, char b) {
  int len = strlen(s);
  maxlast = maxfirst = minlast = minfirst = 0;
  long long y = 0, mx = 0, mi = 0;
  for (int i = 0; i < len; i++) {
    if (s[i] == a) y++;
    if (s[i] == b) y--;
    if (mx < y) {
      mx = y;
      maxlast = maxfirst = i;
    }
    if (mx == y) maxlast = i;
    if (mi > y) {
      mi = y;
      minlast = minfirst = i;
    }
    if (mi == y) minlast = i;
  }
  return mx - mi + 1;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", s);
    int f1 = 0, f2 = 0;
    long long n = solve('W', 'S');
    if ((maxlast < minfirst || minlast < maxfirst) && n > 2) f1 = 1;
    long long m = solve('A', 'D');
    if ((maxlast < minfirst || minlast < maxfirst) && m > 2) f2 = 1;
    long long ans = n * m;
    if (f1 && f2)
      ans = min(n * (m - 1), m * (n - 1));
    else if (f1)
      ans = m * (n - 1);
    else if (f2)
      ans = n * (m - 1);
    printf("%lld\n", ans);
  }
  return 0;
}
