#include <bits/stdc++.h>
int Max(int* a, int b, int* l_p, int* f_p, int j) {
  if (b == *a) {
    *a = b;
    *l_p = j;
  } else if (b > *a) {
    *a = b;
    *l_p = j;
    *f_p = j;
  }
  return 0;
}
int Min(int* a, int b, int* l_p, int* f_p, int j) {
  if (b == *a) {
    *a = b;
    *l_p = j;
  } else if (b < *a) {
    *a = b;
    *l_p = j;
    *f_p = j;
  }
  return 0;
}
long long min(long long a, long long b) { return a < b ? a : b; }
int main() {
  int T;
  scanf("%d", &T);
  for (int i = 0; i < T; i++) {
    char move[200005];
    scanf("%s", move);
    int init_v = 0, init_h = 0;
    int min_x = 0, min_y = 0, max_x = 0, max_y = 0;
    int l_min_x = 0, l_max_x = 0, l_min_y = 0, l_max_y = 0;
    int f_min_x = 0, f_max_x = 0, f_min_y = 0, f_max_y = 0;
    for (int j = 0; j < strlen(move); j++) {
      if (move[j] == 'W') {
        init_v++;
        Max(&max_y, init_v, &l_max_y, &f_max_y, j);
      } else if (move[j] == 'S') {
        init_v--;
        Min(&min_y, init_v, &l_min_y, &f_min_y, j);
      } else if (move[j] == 'A') {
        init_h--;
        Min(&min_x, init_h, &l_min_x, &f_min_x, j);
      } else if (move[j] == 'D') {
        init_h++;
        Max(&max_x, init_h, &l_max_x, &f_max_x, j);
      }
    }
    int x_l = (max_x - min_x + 1);
    int y_l = (max_y - min_y + 1);
    int m_y_l = y_l;
    int m_x_l = x_l;
    if (l_min_x < f_max_x && (max_x - min_x) >= 2) {
      m_x_l--;
    }
    if (l_max_x < f_min_x && (max_x - min_x) >= 2) {
      m_x_l--;
    }
    if (l_min_y < f_max_y && (max_y - min_y) >= 2) {
      m_y_l--;
    }
    if (l_max_y < f_min_y && (max_y - min_y) >= 2) {
      m_y_l--;
    }
    long long ans = min((long long)(x_l) * (long long)m_y_l,
                        (long long)m_x_l * (long long)y_l);
    printf("%lld\n", ans);
  }
  return 0;
}
