#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
bool calc(int &dx, const string &s, char l, char r) {
  int minv = 0, maxv = 0, cur = 0;
  vector<int> traj;
  traj.push_back(0);
  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] == l) {
      cur--;
      minv = min(minv, cur);
    } else if (s[i] == r) {
      cur++;
      maxv = max(maxv, cur);
    }
    traj.push_back(cur);
  }
  dx = maxv - minv + 1;
  if (dx <= 2) return false;
  vector<int> occmin, occmax;
  for (int i = 0; i < traj.size(); i++) {
    int p = traj[i];
    if (p == maxv) occmax.push_back(i);
    if (p == minv) occmin.push_back(i);
  }
  if (maxv != 0 && occmin.back() < occmax[0]) return true;
  if (minv != 0 && occmax.back() < occmin[0]) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    string s;
    cin >> s;
    int dx, dy;
    bool x_ok = calc(dx, s, 'A', 'D');
    bool y_ok = calc(dy, s, 'S', 'W');
    long long ans = (long long)dx * dy;
    if (x_ok) ans = min(ans, (long long)(dx - 1) * dy);
    if (y_ok) ans = min(ans, (long long)dx * (dy - 1));
    cout << ans << '\n';
  }
  return 0;
}
