#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    auto get = [&](string t) {
      int x = 0, low = 0, high = 0;
      for (char &c : t) {
        if (c == 'W' || c == 'D') {
          x++;
        } else {
          x--;
        }
        low = min(low, x);
        high = max(high, x);
      }
      return (long long)high - low + 1;
    };
    string xs, ys;
    for (char &c : s) {
      if (c == 'W' || c == 'S') {
        xs += c;
      } else {
        ys += c;
      }
    }
    int len_x = get(xs), len_y = get(ys);
    long long ans = (long long)len_x * len_y;
    vector<int> pre_x(xs.size() + 1), pre_y(ys.size() + 1);
    for (int i = 0; i < (int)xs.size(); i++) {
      pre_x[i + 1] = pre_x[i] + (xs[i] == 'W' ? 1 : -1);
    }
    for (int i = 0; i < (int)ys.size(); i++) {
      pre_y[i + 1] = pre_y[i] + (ys[i] == 'D' ? 1 : -1);
    }
    int mi = min_element(pre_x.begin(), pre_x.end()) - pre_x.begin();
    int ma = max_element(pre_x.begin(), pre_x.end()) - pre_x.begin();
    if (mi > 0) {
      ans =
          min(ans, get(xs.substr(0, mi - 1) + 'W' + xs.substr(mi - 1)) * len_y);
    }
    if (ma > 0) {
      ans =
          min(ans, get(xs.substr(0, ma - 1) + 'S' + xs.substr(ma - 1)) * len_y);
    }
    mi = min_element(pre_y.begin(), pre_y.end()) - pre_y.begin();
    ma = max_element(pre_y.begin(), pre_y.end()) - pre_y.begin();
    if (mi > 0) {
      ans =
          min(ans, len_x * get(ys.substr(0, mi - 1) + 'D' + ys.substr(mi - 1)));
    }
    if (ma > 0) {
      ans =
          min(ans, len_x * get(ys.substr(0, ma - 1) + 'A' + ys.substr(ma - 1)));
    }
    cout << ans << '\n';
  }
  return 0;
}
