#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int main() {
  int q;
  cin >> q;
  while (q--) {
    string in;
    cin >> in;
    long long x = 0, y = 0;
    long long lmax_y = 0, lmax_x = 0, fmin_x = 0, fmin_y = 0;
    long long fmax_y = 0, fmax_x = 0, lmin_x = 0, lmin_y = 0;
    long long max_y = 0, max_x = 0, min_x = 0, min_y = 0;
    for (int i = 0; i < in.length(); ++i) {
      if (in[i] == 'W') {
        ++y;
        if (max_y < y) {
          fmax_y = i;
          max_y = y;
        } else if (max_y == y)
          lmax_y = i;
      }
      if (in[i] == 'A') {
        --x;
        if (min_x > x) {
          fmin_x = i;
          min_x = x;
        } else if (min_x == x)
          lmin_x = i;
      }
      if (in[i] == 'S') {
        --y;
        if (min_y > y) {
          fmin_y = i;
          min_y = y;
        } else if (min_y == y)
          lmin_y = i;
        ;
      }
      if (in[i] == 'D') {
        ++x;
        if (max_x < x) {
          fmax_x = i;
          max_x = x;
        } else if (max_x == x)
          lmax_x = i;
      }
    }
    long long tmp_min = (max_x - min_x + 1) * (max_y - min_y + 1);
    if (max_x - min_x + 1 > 2 && (lmax_x < fmin_x || lmin_x < fmax_x) &&
        tmp_min > (max_x - min_x) * (max_y - min_y + 1))
      tmp_min = (max_x - min_x) * (max_y - min_y + 1);
    if (max_y - min_y + 1 > 2 && (lmax_y < fmin_y || lmin_y < fmax_y) &&
        tmp_min > (max_x - min_x + 1) * (max_y - min_y))
      tmp_min = (max_x - min_x + 1) * (max_y - min_y);
    cout << tmp_min << "\n";
  }
}
