#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 5;
const int MAXN = 200010;
int T, n;
string s;
int width[MAXN], height[MAXN];
int maxwidth[MAXN], minwidth[MAXN];
int maxheight[MAXN], minheight[MAXN];
int best(int a[], int mx[], int mn[], char le, char ri) {
  for (int i = 1; i <= n; i++) {
    a[i] = a[i - 1];
    if (s[i - 1] == ri) ++a[i];
    if (s[i - 1] == le) --a[i];
  }
  for (int i = n; i >= 0; i--) {
    mx[i] = max(mx[i + 1], a[i]);
    mn[i] = min(mn[i + 1], a[i]);
  }
  int maxlen = 0, minlen = 0;
  int bestlen = mx[0] - mn[0];
  for (int i = 1; i < n; i++) {
    maxlen = max(maxlen, a[i]);
    minlen = min(minlen, a[i]);
    int newmin, newmax;
    newmax = max(mx[i + 1] - 1, maxlen);
    newmin = min(mn[i + 1] - 1, min(a[i] - 1, minlen));
    bestlen = min(bestlen, newmax - newmin);
    newmax = max(mx[i + 1] + 1, max(a[i] + 1, maxlen));
    newmin = min(mn[i + 1] + 1, minlen);
    bestlen = min(bestlen, newmax - newmin);
  }
  return bestlen;
}
void solve() {
  cin >> s;
  n = s.length();
  for (int i = 0; i <= n + 2; i++) {
    height[i] = width[i] = 0;
    maxwidth[i] = maxheight[i] = -INF;
    minwidth[i] = minheight[i] = INF;
  }
  long long besth = best(height, maxheight, minheight, 'S', 'W');
  long long bestw = best(width, maxwidth, minwidth, 'A', 'D');
  long long oldw = maxwidth[0] - minwidth[0];
  long long oldh = maxheight[0] - minheight[0];
  long long ans = (oldw + 1) * (oldh + 1);
  ans = min(ans, (oldw + 1) * (besth + 1));
  ans = min(ans, (oldh + 1) * (bestw + 1));
  cout << ans << "\n";
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> T;
  while (T--) {
    solve();
  }
}
