#include <bits/stdc++.h>   using namespace std;   vector<long long> v[2];   long long get(long long a, long long b) { return (a + b != 0); }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     string s;     long long ans, x, y, a, b, c, d;     long long minx, maxx, miny, maxy, maxl, maxr, maxu, maxd;     while (t--) {       cin >> s;       x = 0;       y = 0;       minx = 0;       maxx = 0;       miny = 0;       maxy = 0;       maxl = 0;       maxr = 0;       maxu = 0;       maxd = 0;       for (auto it : s) {         if (it ==  W ) y++;         if (it ==  S ) y--;         if (it ==  A ) x--;         if (it ==  D ) x++;         maxx = max(maxx, x);         minx = min(minx, x);         maxy = max(maxy, y);         miny = min(miny, y);         maxu = max(maxu, y - miny);         maxd = max(maxd, maxy - y);         maxr = max(maxr, x - minx);         maxl = max(maxl, maxx - x);       }       a = max(maxl, maxr);       b = max(get(maxl, maxr), a - (maxl != maxr));       c = max(maxu, maxd);       d = max(get(maxu, maxd), c - (maxu != maxd));       a++;       b++;       c++;       d++;       ans = min(a * d, b * c);       cout << ans <<   n ;     }     return 0;   }   