#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 100;
struct node {
  long long minx, miny, maxx, maxy;
} aa[maxn], bb[maxn];
char a[maxn];
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    cin >> (a + 1);
    a[0] = ' ';
    int len = strlen(a) - 1;
    long long x = 0, y = 0;
    for (int i = 1; i <= len; i++) {
      if (a[i] == 'D') {
        x++;
        a[i] = 'A';
      } else if (a[i] == 'S') {
        y--;
        a[i] = 'W';
      } else if (a[i] == 'A') {
        x--;
        a[i] = 'D';
      } else if (a[i] == 'W') {
        a[i] = 'S';
        y++;
      }
      aa[i].maxx = max(aa[i - 1].maxx, x);
      aa[i].maxy = max(aa[i - 1].maxy, y);
      aa[i].minx = min(aa[i - 1].minx, x);
      aa[i].miny = min(aa[i - 1].miny, y);
    }
    bb[len].maxx = bb[len].minx = x;
    bb[len].maxy = bb[len].miny = y;
    for (int i = len; i >= 1; i--) {
      if (a[i] == 'D') {
        x++;
      }
      if (a[i] == 'S') {
        y--;
      }
      if (a[i] == 'A') {
        x--;
      }
      if (a[i] == 'W') {
        y++;
      }
      bb[i - 1].maxx = max(bb[i].maxx, x);
      bb[i - 1].maxy = max(bb[i].maxy, y);
      bb[i - 1].minx = min(bb[i].minx, x);
      bb[i - 1].miny = min(bb[i].miny, y);
    }
    long long ans = 999999999999, xx, yy, xxx, yyy;
    for (int i = 0; i < len; i++) {
      xx = min(aa[i].minx, bb[i].minx - 1);
      yy = min(aa[i].miny, bb[i].miny);
      xxx = max(aa[i].maxx, bb[i].maxx - 1);
      yyy = max(aa[i].maxy, bb[i].maxy);
      ans = min(ans, (xxx - xx + 1) * (yyy - yy + 1));
      xx = min(aa[i].minx, bb[i].minx + 1);
      yy = min(aa[i].miny, bb[i].miny);
      xxx = max(aa[i].maxx, bb[i].maxx + 1);
      yyy = max(aa[i].maxy, bb[i].maxy);
      ans = min(ans, (xxx - xx + 1) * (yyy - yy + 1));
      xx = min(aa[i].minx, bb[i].minx);
      yy = min(aa[i].miny, bb[i].miny - 1);
      xxx = max(aa[i].maxx, bb[i].maxx);
      yyy = max(aa[i].maxy, bb[i].maxy - 1);
      ans = min(ans, (xxx - xx + 1) * (yyy - yy + 1));
      xx = min(aa[i].minx, bb[i].minx);
      yy = min(aa[i].miny, bb[i].miny + 1);
      xxx = max(aa[i].maxx, bb[i].maxx);
      yyy = max(aa[i].maxy, bb[i].maxy + 1);
      ans = min(ans, (xxx - xx + 1) * (yyy - yy + 1));
    }
    cout << ans << endl;
  }
  return 0;
}
