#include <bits/stdc++.h>
using namespace std;
int x, y, l, r, u, d;
int lowl, highl, lowr, highr;
int lowu, highu, lowd, highd;
int nd, nu, nl, nr;
long long res, s;
string rb;
void Solve() {
  x = y = 0;
  l = r = u = d = 0;
  lowl = lowu = lowr = lowd = 0;
  highl = highu = highr = highd = 0;
  for (int i = 0; i < (int)rb.size(); i++) {
    if (rb[i] == 'S') {
      x++;
      if (x > d) {
        d = x;
        lowd = highd = i;
      } else if (x == d)
        highd = i;
    } else if (rb[i] == 'W') {
      x--;
      if (x < u) {
        u = x;
        lowu = highu = i;
      } else if (x == u)
        highu = i;
    } else if (rb[i] == 'A') {
      y--;
      if (y < l) {
        l = y;
        lowl = highl = i;
      } else if (y == l)
        highl = i;
    } else {
      y++;
      if (y > r) {
        r = y;
        lowr = highr = i;
      } else if (y == r)
        highr = i;
    }
  }
  res = (d - u + 1) * ((long long)r - l + 1);
  nd = d;
  nu = u;
  nd--;
  if (lowd <= highu) nu--;
  nu = min(nu, nd - 1);
  s = (nd - nu + 1) * ((long long)r - l + 1);
  res = min(res, s);
  nd = d;
  nu = u;
  nu++;
  if (lowu <= highd) nd++;
  nd = max(nd, nu + 1);
  s = (nd - nu + 1) * ((long long)r - l + 1);
  res = min(res, s);
  nr = r;
  nl = l;
  nr--;
  if (lowr <= highl) nl--;
  nl = min(nr - 1, nl);
  s = (d - u + 1) * ((long long)nr - nl + 1);
  res = min(res, s);
  nl = l;
  nr = r;
  nl++;
  if (lowl <= highr) nr++;
  nr = max(nl + 1, nr);
  s = (d - u + 1) * ((long long)nr - nl + 1);
  res = min(res, s);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    cin >> rb;
    Solve();
    cout << res << '\n';
  }
}
