#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e6 + 50;
char s[maxn];
struct date {
  long long x, y;
} a[maxn];
int main() {
  long long t;
  scanf("%I64d", &t);
  while (t--) {
    scanf("%s", s);
    long long max = 0, mix = 0, may = 0, miy = 0;
    long long cax1 = 0, cix1 = 0, cay1 = 0, ciy1 = 0;
    long long len = strlen(s);
    long long x = 0, y = 0;
    for (long long i = 0; i < len; i++) {
      if (s[i] == 'W') {
        y++;
      } else if (s[i] == 'S') {
        y--;
      } else if (s[i] == 'D') {
        x++;
      } else if (s[i] == 'A') {
        x--;
      }
      a[i].x = x;
      a[i].y = y;
      if (x > max) {
        max = x;
        cax1 = i;
      }
      if (x < mix) {
        mix = x;
        cix1 = i;
      }
      if (y > may) {
        may = y;
        cay1 = i;
      }
      if (y < miy) {
        miy = y;
        ciy1 = i;
      }
    }
    if (len == 1) {
      printf("2\n");
      continue;
    }
    long long ans = (max - mix + 1) * (may - miy + 1);
    long long flag = 1;
    for (long long i = cix1 + 1; i < len; i++) {
      if (a[i].x == max) {
        flag = 0;
        break;
      }
    }
    if (flag && max - mix > 1) {
      ans = min(ans, (max - mix) * (may - miy + 1));
    }
    flag = 1;
    for (long long i = cax1; i < len; i++) {
      if (a[i].x == mix) {
        flag = 0;
        break;
      }
    }
    if (flag && max - mix > 1) {
      ans = min(ans, (max - mix) * (may - miy + 1));
    }
    flag = 1;
    for (long long i = ciy1 + 1; i < len; i++) {
      if (a[i].y == may) {
        flag = 0;
        break;
      }
    }
    if (flag && may - miy > 1) {
      ans = min(ans, (max - mix + 1) * (may - miy));
    }
    flag = 1;
    for (long long i = cay1 + 1; i < len; i++) {
      if (a[i].y == miy) {
        flag = 0;
        break;
      }
    }
    if (flag && may - miy > 1) {
      ans = min(ans, (max - mix + 1) * (may - miy));
    }
    printf("%I64d\n", ans);
  }
}
