#include <bits/stdc++.h>   template <typename T>   class IntegerIterator {    public:     using value_type = T;     using difference_type = std::ptrdiff_t;     using pointer = T *;     using reference = T;     using iterator_category = std::input_iterator_tag;     explicit IntegerIterator(T value) : value(value) {}     IntegerIterator &operator++() {       ++value;       return *this;     }     IntegerIterator operator++(int) {       IntegerIterator copy = *this;       ++value;       return copy;     }     IntegerIterator &operator--() {       --value;       return *this;     }     IntegerIterator operator--(int) {       IntegerIterator copy = *this;       --value;       return copy;     }     T operator*() const { return value; }     bool operator==(IntegerIterator rhs) const { return value == rhs.value; }     bool operator!=(IntegerIterator rhs) const { return !(*this == rhs); }       private:     T value;   };   template <typename T>   class IntegerRange {    public:     IntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }     IntegerIterator<T> begin() const { return IntegerIterator<T>(begin_); }     IntegerIterator<T> end() const { return IntegerIterator<T>(end_); }       private:     T begin_;     T end_;   };   template <typename T>   class ReversedIntegerRange {     using IteratorType = std::reverse_iterator<IntegerIterator<T>>;       public:     ReversedIntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }     IteratorType begin() const {       return IteratorType(IntegerIterator<T>(begin_));     }     IteratorType end() const { return IteratorType(IntegerIterator<T>(end_)); }       private:     T begin_;     T end_;   };   template <typename T>   IntegerRange<T> range(T to) {     return IntegerRange<T>(0, to);   }   template <typename T>   IntegerRange<T> range(T from, T to) {     return IntegerRange<T>(from, to);   }   template <typename T>   IntegerRange<T> inclusiveRange(T to) {     return IntegerRange<T>(0, to + 1);   }   template <typename T>   IntegerRange<T> inclusiveRange(T from, T to) {     return IntegerRange<T>(from, to + 1);   }   template <typename T>   ReversedIntegerRange<T> downrange(T from) {     return ReversedIntegerRange<T>(from, 0);   }   template <typename T>   ReversedIntegerRange<T> downrange(T from, T to) {     return ReversedIntegerRange<T>(from, to);   }   template <typename T>   ReversedIntegerRange<T> inclusiveDownrange(T from) {     return ReversedIntegerRange<T>(from + 1, 0);   }   template <typename T>   ReversedIntegerRange<T> inclusiveDownrange(T from, T to) {     return ReversedIntegerRange<T>(from + 1, to);   }   using namespace std;   class CYouAreGivenAWASDString {    public:     void solve(std::istream &in, std::ostream &out) {       int t;       in >> t;       while (t--) {         string str;         in >> str;         int n = str.size();         vector<int> maxx1(n + 1), minx1(n + 1), maxy1(n + 1), miny1(n + 1),             maxx2(n + 1), maxy2(n + 1), minx2(n + 1), miny2(n + 1);         int x = 0, y = 0;         for (int i : range(n)) {           if (str[i] ==  W ) {             y++;           } else if (str[i] ==  S ) {             y--;           } else if (str[i] ==  A ) {             x--;           } else {             x++;           }           minx1[i + 1] = min(minx1[i], x);           maxx1[i + 1] = max(maxx1[i], x);           miny1[i + 1] = min(miny1[i], y);           maxy1[i + 1] = max(maxy1[i], y);         }         minx2[n] = maxx2[n] = x;         miny2[n] = maxy2[n] = y;         for (int i : downrange(n)) {           if (str[i] ==  W ) {             y--;           } else if (str[i] ==  S ) {             y++;           } else if (str[i] ==  A ) {             x++;           } else {             x--;           }           minx2[i] = min(minx2[i + 1], x);           maxx2[i] = max(maxx2[i + 1], x);           miny2[i] = min(miny2[i + 1], y);           maxy2[i] = max(maxy2[i + 1], y);         }         long long res =             (long long)(maxx1[n] - minx1[n] + 1) * (maxy1[n] - miny1[n] + 1);         for (int i : inclusiveRange(0, n)) {           for (int j : range(4)) {             int dx = 0, dy = 0;             if (j % 2 == 0) {               if (j / 2) {                 dx = 1;               } else {                 dx = -1;               }             } else {               if (j / 2) {                 dy = 1;               } else {                 dy = -1;               }             }             int maxX = max(maxx1[i], maxx2[i] + dx),                 minX = min(minx1[i], minx2[i] + dx),                 maxY = max(maxy1[i], maxy2[i] + dy),                 minY = min(miny1[i], miny2[i] + dy);             res = min(res, (long long)(maxX - minX + 1) * (maxY - minY + 1));           }         }         out << res <<   n ;       }     }     void setup() {}   };   int main() {     std::ios_base::sync_with_stdio(false);     CYouAreGivenAWASDString solver;     solver.setup();     std::istream &in(std::cin);     std::ostream &out(std::cout);     in.tie(nullptr);     out << std::fixed;     out.precision(20);     solver.solve(in, out);     return 0;   }