#include <bits/stdc++.h>   using namespace std;   int t;   long long l[200002], c[200002];   long long minx, maxx, miny, maxy;   string s;   bool check(long long l[], int n) {     int Min = 0, Max = 0;     int last = 0, first = 0;     for (int i = 1; i <= n; i++) {       if (l[i] < Min) {         first = i;         Min = l[i];       }       if (l[i] >= Max) {         last = i;         Max = l[i];       }     }     if (last < first) return 1;     Min = 0, Max = 0;     first = last = 0;     for (int i = 1; i <= n; i++) {       if (l[i] > Max) {         first = i;         Max = l[i];       }       if (l[i] <= Min) {         Min = l[i];         last = i;       }     }     if (last < first) return 1;     return 0;   }   int main() {     cin >> t;     while (t--) {       cin >> s;       minx = maxx = miny = maxy = 0;       long long x = 0, y = 0;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  D ) c[i + 1] = c[i] + 1;         if (s[i] ==  A ) c[i + 1] = c[i] - 1;         if (s[i] ==  W ) l[i + 1] = l[i] + 1;         if (s[i] ==  S ) l[i + 1] = l[i] - 1;         if (s[i] ==  W  || s[i] ==  S ) c[i + 1] = c[i];         if (s[i] ==  D  || s[i] ==  A ) l[i + 1] = l[i];         minx = min(minx, l[i + 1]);         miny = min(miny, c[i + 1]);         maxx = max(maxx, l[i + 1]);         maxy = max(maxy, c[i + 1]);       }       long long ans = (maxx - minx + 1) * (maxy - miny + 1);       if (check(l, s.size()) && maxx - minx + 1 > 2)         ans = min(ans, (maxx - minx) * (maxy - miny + 1));       if (check(c, s.size()) && maxy - miny + 1 > 2)         ans = min(ans, (maxx - minx + 1) * (maxy - miny));       cout << ans <<   n ;     }     return 0;   }   