#include <bits/stdc++.h>
using namespace std;
const int maxn = 40000;
char s[200020];
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> s;
    int l = 0, r = 0, lmax = 0, lmin = 0, rmin = 0, rmax = 0, lmaxlen = 0,
        lminlen = 0, rminlen = 0, rmaxlen = 0;
    int n = strlen(s);
    for (int i = 0; i < n; i++) {
      if (s[i] == 'W') {
        l++;
        lmax = max(lmax, l);
      } else if (s[i] == 'S') {
        l--;
        lmin = min(lmin, l);
      } else if (s[i] == 'D') {
        r++;
        rmax = max(rmax, r);
      } else {
        r--;
        rmin = min(rmin, r);
      }
      lmaxlen = max(lmaxlen, lmax - l);
      lminlen = max(lminlen, l - lmin);
      rmaxlen = max(rmaxlen, rmax - r);
      rminlen = max(rminlen, r - rmin);
    }
    long long ans = 1ll * (lmax - lmin + 1) * (rmax - rmin + 1);
    if (lmax - lmin > 1 && lmaxlen != lminlen) {
      ans = min(ans, 1ll * (lmax - lmin) * (rmax - rmin + 1));
    }
    if (rmax - rmin > 1 && rmaxlen != rminlen) {
      ans = min(ans, 1ll * (lmax - lmin + 1) * (rmax - rmin));
    }
    cout << ans << endl;
  }
}
