#include <bits/stdc++.h>
using namespace std;
const int INF = 2 * 1e5 + 1;
int v[INF];
int h[INF];
pair<int, long long int> diminui(int a, int arr[]) {
  int mx = 0;
  int mn = 0;
  int pmx = 0;
  int umn = 0;
  for (int i = 0; i < a; i++) {
    if (arr[i] > mx) {
      mx = arr[i];
      pmx = i;
    } else if (arr[i] <= mn) {
      mn = arr[i];
      umn = i;
    }
  }
  return make_pair(umn + 1 < pmx, mx - mn + 1);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string str;
    cin >> str;
    int vp = 1, hp = 1;
    for (int i = 0; i < str.size(); i++) {
      if (str[i] == 'W') {
        v[vp] = v[vp - 1] + 1;
        vp++;
      } else if (str[i] == 'S') {
        v[vp] = v[vp - 1] - 1;
        vp++;
      } else if (str[i] == 'A') {
        h[hp] = h[hp - 1] + 1;
        hp++;
      } else {
        h[hp] = h[hp - 1] - 1;
        hp++;
      }
    }
    pair<int, int> a = diminui(hp, h);
    pair<int, int> w = diminui(vp, v);
    for (int i = 0; i < hp; i++) {
      h[i] *= -1;
    }
    for (int i = 0; i < vp; i++) {
      v[i] *= -1;
    }
    pair<int, int> d = diminui(hp, h);
    pair<int, int> s = diminui(vp, v);
    if (d.second > s.second) {
      if (s.first || w.first) {
        (s.second)--;
      } else if (a.first || d.first) {
        (a.second)--;
      }
    } else {
      if (a.first || d.first) {
        (a.second)--;
      } else if (s.first || w.first) {
        (s.second)--;
      }
    }
    long long int ans = (long long int)a.second * s.second;
    cout << ans << endl;
  }
}
