#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 2000010
#define INF 0x3f3f3f3f
char s[N];
int Left[N], Right[N], Up[N], Down[N];
void change(int &x, int &y, char c) {
if (c == 'W') {
++y;
} else if (c == 'A') {
--x;
} else if (c == 'S') {
--y;
} else if (c == 'D') {
++x;
}
}
int main() {
#ifdef LOCAL_JUDGE
freopen("input.txt", "r", stdin);
#endif
int T;
scanf("%d", &T);
while (T--) {
scanf("%s", s + 1);
int len = strlen(s + 1);
int x = 0, y = 0;
int x1 = INF, x2 = INF, y1 = INF, y2 = INF;
int left = 0, right = 0, up = 0, down = 0;
for (int i = 1; i <= len; ++i) {
change(x, y, s[i]);
if (left > x) {
x1 = i;
left = x;
}
if (right < x) {
x2 = i;
right = x;
}
if (up < y) {
y1 = i;
up = y;
}
if (down > y) {
y2 = i;
down = y;
}
}
ll ans = 1ll * (up - down + 1) * (right - left + 1);
if (x1 != INF) {
x = y = left = right = up = down = 0;
for (int i = 1; i <= len; ++i) {
if (i == x1) {
change(x, y, 'D');
left = min(left, x);
right = max(right, x);
up = max(up, y);
down = min(down, y);
}
change(x, y, s[i]);
left = min(left, x);
right = max(right, x);
up = max(up, y);
down = min(down, y);
}
ans = min(ans, 1ll * (up - down + 1) * (right - left + 1));
}
if (x2 != INF) {
x = y = left = right = up = down = 0;
for (int i = 1; i <= len; ++i) {
if (i == x2) {
change(x, y, 'A');
left = min(left, x);
right = max(right, x);
up = max(up, y);
down = min(down, y);
}
change(x, y, s[i]);
left = min(left, x);
right = max(right, x);
up = max(up, y);
down = min(down, y);
}
ans = min(ans, 1ll * (up - down + 1) * (right - left + 1));
}
if (y1 != INF) {
x = y = left = right = up = down = 0;
for (int i = 1; i <= len; ++i) {
if (i == y1) {
change(x, y, 'S');
left = min(left, x);
right = max(right, x);
up = max(up, y);
down = min(down, y);
}
change(x, y, s[i]);
left = min(left, x);
right = max(right, x);
up = max(up, y);
down = min(down, y);
}
ans = min(ans, 1ll * (up - down + 1) * (right - left + 1));
}
if (y2 != INF) {
x = y = left = right = up = down = 0;
for (int i = 1; i <= len; ++i) {
if (i == y2) {
change(x, y, 'W');
left = min(left, x);
right = max(right, x);
up = max(up, y);
down = min(down, y);
}
change(x, y, s[i]);
left = min(left, x);
right = max(right, x);
up = max(up, y);
down = min(down, y);
}
ans = min(ans, 1ll * (up - down + 1) * (right - left + 1));
}
printf("%lld\n", ans);
}
return 0;
}