#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
pair<int, int> solve(vector<int>& a) {
  int n = (int)a.size();
  int sum = 0, mx = 0, mn = 0;
  for (int i = 0; i < n; ++i) {
    sum += a[i];
    mx = max(mx, sum);
    mn = min(mn, sum);
  }
  int ans = mx - mn + 1;
  sum = 0;
  int lmx = -1, rmx, lmn = -1, rmn;
  if (sum == mx) {
    if (lmx == -1) lmx = 0;
    rmx = 0;
  }
  if (sum == mn) {
    if (lmn == -1) lmn = 0;
    rmn = 0;
  }
  for (int i = 0; i < n; ++i) {
    sum += a[i];
    if (sum == mx) {
      if (lmx == -1) lmx = i + 1;
      rmx = i + 1;
    }
    if (sum == mn) {
      if (lmn == -1) lmn = i + 1;
      rmn = i + 1;
    }
  }
  int delt = 0;
  if (rmn + 1 < lmx || rmx + 1 < lmn) delt = -1;
  return {ans, delt};
}
void solve() {
  string s;
  cin >> s;
  vector<int> a, b;
  for (char c : s) {
    if (c == 'W')
      a.push_back(1);
    else if (c == 'S')
      a.push_back(-1);
    else if (c == 'A')
      b.push_back(-1);
    else if (c == 'D')
      b.push_back(1);
  }
  pair<int, int> pa = solve(a), pb = solve(b);
  cout << min((pa.first + pa.second) * 1LL * pb.first,
              pa.first * 1LL * (pb.first + pb.second))
       << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t;
  cin >> t;
  while (t--) solve();
}
