#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long first = 0, second = 0;
    char c[200005];
    scanf("%s", c);
    long long Minx = 0, Maxx = 0, Miny = 0, Maxy = 0;
    vector<int> xr, yr;
    xr.push_back(0);
    yr.push_back(0);
    for (int i = 0; c[i] != 0; i++) {
      if (c[i] == 'W') first++;
      if (c[i] == 'S') first--;
      if (c[i] == 'A') second--;
      if (c[i] == 'D') second++;
      Minx = min(Minx, first);
      Miny = min(Miny, second);
      Maxx = max(Maxx, first);
      Maxy = max(Maxy, second);
      xr.push_back(first);
      yr.push_back(second);
    }
    int l = 1e9, r = xr.size() - 1;
    int okx = 0, oky = 0;
    for (int i = 0; i < xr.size(); i++) {
      if (xr[i] == Maxx) {
        l = min(l, i);
      }
    }
    if (l != 0 && xr[l - 1] != Minx) {
      int ook = 1;
      for (int i = l; i <= r; i++) {
        if (xr[i] == Minx) {
          ook = 0;
        }
      }
      if (ook) okx = 1;
    }
    l = 1e9, r = xr.size() - 1;
    for (int i = 0; i < xr.size(); i++) {
      if (xr[i] == Minx) {
        l = min(l, i);
      }
    }
    if (l != 0 && xr[l - 1] != Maxx) {
      int ook = 1;
      for (int i = l; i <= r; i++) {
        if (xr[i] == Maxx) {
          ook = 0;
        }
      }
      if (ook) okx = 1;
    }
    l = 1e9, r = yr.size() - 1;
    for (int i = 0; i < yr.size(); i++) {
      if (yr[i] == Miny) {
        l = min(l, i);
      }
    }
    if (l != 0 && yr[l - 1] != Maxy) {
      int ook = 1;
      for (int i = l; i <= r; i++) {
        if (yr[i] == Maxy) {
          ook = 0;
        }
      }
      if (ook) oky = 1;
    }
    l = 1e9, r = yr.size() - 1;
    for (int i = 0; i < yr.size(); i++) {
      if (yr[i] == Maxy) {
        l = min(l, i);
        r = max(r, i);
      }
    }
    if (l != 0 && yr[l - 1] != Miny) {
      int ook = 1;
      for (int i = l; i <= r; i++) {
        if (yr[i] == Miny) {
          ook = 0;
        }
      }
      if (ook) oky = 1;
    }
    printf("%lld\n", min((Maxx - Minx + 1 - okx) * (Maxy - Miny + 1),
                         (Maxx - Minx + 1) * (Maxy - Miny + 1 - oky)));
  }
  return 0;
}
