#include <bits/stdc++.h>   using namespace std;   int bst(int a[], int lw, int hi, int n) {     int mid = (lw + hi) / 2;     if (lw > hi) return -1;     if (a[mid] > n)       bst(a, lw, mid - 1, n);     else if (a[mid] < n)       bst(a, mid + 1, hi, n);     else       return mid;   }   long long pw(long long a, long long b, long long p) {     if (b == 0) return 1;     long long t = pw(a, b / 2, p);     if (b % 2)       return (((a * t) % p) * t) % p;     else       return ((t * t) % p);   }   void solve() {     string s;     long long ct1 = 0, ct2 = 0, V = 0, H = 0;     cin >> s;     if (s.size() == 1) {       cout << 2 << endl;       return;     }     vector<long long> v1, v2;     v1.push_back(0);     v2.push_back(0);     long long i = 0, k = 0, t = 0;     while (i < s.size()) {       if (s[i] ==  W ) {         v1.push_back(++ct1);       } else if (s[i] ==  S ) {         v1.push_back(--ct1);       } else if (s[i] ==  D ) {         v2.push_back(++ct2);       } else {         v2.push_back(--ct2);       }       i++;     }     if (v1.size() == 2) {       V = 1;     }     if (v2.size() == 2) {       H = 1;     }     long long lw1 = *min_element(v1.begin(), v1.end()),               hi1 = *max_element(v1.begin(), v1.end());     long long lw2 = *min_element(v2.begin(), v2.end()),               hi2 = *max_element(v2.begin(), v2.end());     vector<long long> min1_pos, min2_pos, max1_pos, max2_pos;     for (i = 0; i < v1.size(); i++) {       if (v1[i] == lw1) min1_pos.push_back(i);       if (v1[i] == hi1) max1_pos.push_back(i);     }     for (i = 0; i < v2.size(); i++) {       if (v2[i] == lw2) min2_pos.push_back(i);       if (v2[i] == hi2) max2_pos.push_back(i);     }     bool v, h;     long long a, b, c, d;     a = min1_pos.back();     b = min1_pos.front();     c = max1_pos.back();     d = max1_pos.front();     if ((c < a && c < b) || (d > a && d > b))       v = true;     else       v = false;     a = min2_pos.back();     b = min2_pos.front();     c = max2_pos.back();     d = max2_pos.front();     if ((c < a && c < b) || (d > a && d > b))       h = true;     else       h = false;     if (V && H) {       cout << 4 << endl;     } else if (V) {       if (h)         cout << 2 * (hi2 - lw2) << endl;       else         cout << 2 * (hi2 - lw2 + 1) << endl;     } else if (H) {       if (v)         cout << 2 * (hi1 - lw1) << endl;       else         cout << 2 * (hi1 - lw1 + 1) << endl;     } else {       if (v && h)         cout << min((hi1 - lw1 + 1) * (hi2 - lw2), (hi1 - lw1) * (hi2 - lw2 + 1))              << endl;       else if (v)         cout << (hi1 - lw1) * (hi2 - lw2 + 1) << endl;       else if (h)         cout << (hi1 - lw1 + 1) * (hi2 - lw2) << endl;       else         cout << (hi1 - lw1 + 1) * (hi2 - lw2 + 1) << endl;     }   }   int main() {     long long t = 1;     cin >> t;     while (t--) solve();     return 0;   }   