#include <bits/stdc++.h>
using namespace std;
char form[200005];
int actions[2][200005], mem[2];
int brack_par[200005], no_change[2], changed[2];
int pre_min[200005], pre_max[200005];
void process(int par) {
  for (int i = 1; i <= mem[par]; i++) {
    brack_par[i] = brack_par[i - 1] + actions[par][i];
    pre_min[i] = min(pre_min[i - 1], brack_par[i]);
    pre_max[i] = max(pre_max[i - 1], brack_par[i]);
  }
  no_change[par] = changed[par] = pre_max[mem[par]] - pre_min[mem[par]] + 1;
  int nex_min = (int)1e9, nex_max = -(int)1e9;
  for (int i = mem[par]; i > 1; i--) {
    nex_min = min(nex_min, brack_par[i]);
    nex_max = max(nex_max, brack_par[i]);
    int all_max = max(nex_max + 1, pre_max[i - 1]);
    int all_min = min(nex_min + 1, pre_min[i - 1]);
    changed[par] = min(changed[par], all_max - all_min + 1);
    all_max = max(nex_max - 1, pre_max[i - 1]);
    all_min = min(nex_min - 1, pre_min[i - 1]);
    changed[par] = min(changed[par], all_max - all_min + 1);
  }
}
void solve() {
  scanf("%s", form + 1);
  int length = strlen(form + 1);
  mem[0] = mem[1] = 0;
  for (int i = 1; i <= length; i++)
    if (form[i] == 'W')
      actions[0][++mem[0]] = 1;
    else if (form[i] == 'S')
      actions[0][++mem[0]] = -1;
    else if (form[i] == 'D')
      actions[1][++mem[1]] = 1;
    else
      actions[1][++mem[1]] = -1;
  process(0), process(1);
  long long res = min((long long)changed[0] * no_change[1],
                      (long long)no_change[0] * changed[1]);
  printf("%lld\n", res);
}
int main() {
  int tester;
  scanf("%d", &tester);
  while (tester--) solve();
}
