#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 15;
char s[N];
int maxi[N], mini[N];
pair<int, int> getLen(vector<int> &in) {
  int ret = 1e9;
  int n = in.size();
  maxi[n] = mini[n] = 0;
  int tmpMaxi = 0, tmpMini = 0;
  int cur = 0;
  for (int i = n - 1; i >= 0; --i) {
    int tmp = in[i];
    maxi[i] = max(tmp, tmp + maxi[i + 1]);
    mini[i] = min(tmp, tmp + mini[i + 1]);
    maxi[i] = max(maxi[i], 0);
    mini[i] = min(mini[i], 0);
  }
  ret = maxi[0] - mini[0] + 1;
  cur = 0;
  for (int i = 0; i <= in.size(); ++i) {
    for (int j = -1; j <= 1; j += 2) {
      int tmpCur = cur + j;
      int cmaxi = max(tmpCur + maxi[i], tmpMaxi);
      int cmini = min(tmpCur + mini[i], tmpMini);
      ret = min(ret, cmaxi - cmini + 1);
    }
    if (i == in.size()) {
      break;
    } else {
      cur += in[i];
      tmpMaxi = max(tmpMaxi, cur);
      tmpMini = min(tmpMini, cur);
    }
  }
  return make_pair(maxi[0] - mini[0] + 1, ret);
}
void solve() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", s);
    int n = strlen(s);
    vector<int> X, Y;
    for (int i = 0; i < n; ++i) {
      if (s[i] == 'W') {
        Y.push_back(1);
      } else if (s[i] == 'S') {
        Y.push_back(-1);
      } else if (s[i] == 'A') {
        X.push_back(1);
      } else if (s[i] == 'D') {
        X.push_back(-1);
      } else {
        assert(0);
      }
    }
    pair<int, int> x = getLen(X);
    pair<int, int> y = getLen(Y);
    long long ret = (long long)x.first * y.second;
    ret = min(ret, (long long)x.second * y.first);
    printf("%lld\n", ret);
  }
}
int main() { solve(); }
