#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long MOD = 1000000007;
double eps = 1e-12;
const int N = 2e5 + 7;
int n;
string str;
map<char, int> mp1;
long long ans = 2e18;
void solve() {
  mp1.clear();
  cin >> str;
  ans = 2e18;
  n = ((long long)(str).size());
  mp1['W'] = 1;
  mp1['S'] = -1;
  mp1['A'] = -1;
  mp1['D'] = 1;
  int cr = 0, cc = 0;
  vector<int> vechor, vecver;
  vecver.push_back(0);
  vechor.push_back(0);
  int mnr = 0, mxr = 0, mnc = 0, mxc = 0;
  for (long long i = 0; i <= n - 1; i++) {
    if (str[i] == 'W' or str[i] == 'S') {
      cc += mp1[str[i]];
      vecver.push_back(cc);
      mnc = min(mnc, cc);
      mxc = max(mxc, cc);
    } else {
      cr += mp1[str[i]];
      vechor.push_back(cr);
      mnr = min(mnr, cr);
      mxr = max(mxr, cr);
    }
  }
  ans = min(ans, (long long)(mxr - mnr + 1) * (mxc - mnc + 1));
  vector<int> tmp;
  int pos = -1;
  for (long long i = ((long long)(vecver).size()) - 1; i >= 0; i--) {
    if (vecver[i] == mxc) {
      pos = i;
      break;
    }
  }
  tmp = vecver;
  for (long long i = pos + 2; i <= ((long long)(tmp).size()) - 1; i++)
    tmp[i] += 1;
  int tmpmnc = N;
  for (long long i = 0; i <= ((long long)(tmp).size()) - 1; i++)
    tmpmnc = min(tmpmnc, tmp[i]);
  ans = min(ans, (long long)(mxr - mnr + 1) * (mxc - tmpmnc + 1));
  pos = -1;
  for (long long i = ((long long)(vecver).size()) - 1; i >= 0; i--) {
    if (vecver[i] == mnc) {
      pos = i;
      break;
    }
  }
  tmp.clear();
  tmp = vecver;
  for (long long i = pos + 2; i <= ((long long)(tmp).size()) - 1; i++)
    tmp[i] -= 1;
  int tmpmxc = -1;
  for (long long i = 0; i <= ((long long)(tmp).size()) - 1; i++)
    tmpmxc = max(tmpmxc, tmp[i]);
  ans = min(ans, (long long)(mxr - mnr + 1) * (tmpmxc - mnc + 1));
  pos = -1;
  for (long long i = ((long long)(vechor).size()) - 1; i >= 0; i--) {
    if (vechor[i] == mnr) {
      pos = i;
      break;
    }
  }
  tmp.clear();
  tmp = vechor;
  for (long long i = pos + 2; i <= ((long long)(tmp).size()) - 1; i++)
    tmp[i] -= 1;
  int tmpmxr = -1;
  for (long long i = 0; i <= ((long long)(tmp).size()) - 1; i++)
    tmpmxr = max(tmpmxr, tmp[i]);
  ans = min(ans, (long long)(tmpmxr - mnr + 1) * (mxc - mnc + 1));
  pos = -1;
  for (long long i = ((long long)(vechor).size()) - 1; i >= 0; i--) {
    if (vechor[i] == mxr) {
      pos = i;
      break;
    }
  }
  tmp.clear();
  tmp = vechor;
  for (long long i = pos + 2; i <= ((long long)(tmp).size()) - 1; i++)
    tmp[i] += 1;
  int tmpmnr = N;
  for (long long i = 0; i <= ((long long)(tmp).size()) - 1; i++)
    tmpmnr = min(tmpmnr, tmp[i]);
  ans = min(ans, (long long)(mxr - tmpmnr + 1) * (mxc - mnc + 1));
  cout << ans << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  for (int it = 1; it <= t; it++) {
    solve();
  }
  return 0;
}
