#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 7;
const long long MAX = 200010;
const long double EPS = 1e-9;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long t;
  cin >> t;
  while (t) {
    t--;
    string s;
    cin >> s;
    long long n = s.size();
    vector<vector<long long> > rui(n + 1, vector<long long>(4));
    long long nowx = 0, nowy = 0;
    for (long long i = (0); i < (n); i++) {
      if (s[i] == 'D') {
        nowx++;
      } else if (s[i] == 'S') {
        nowy--;
      } else if (s[i] == 'A') {
        nowx--;
      } else {
        nowy++;
      }
      rui[i + 1][0] = max(rui[i][0], nowx);
      rui[i + 1][1] = min(rui[i][1], nowy);
      rui[i + 1][2] = min(rui[i][2], nowx);
      rui[i + 1][3] = max(rui[i][3], nowy);
    }
    long long X = rui[n][0] - rui[n][2] + 1;
    long long Y = rui[n][3] - rui[n][1] + 1;
    long long ans = X * Y;
    vector<vector<long long> > rm(n + 1, vector<long long>(4));
    rm[n][0] = nowx;
    rm[n][1] = nowy;
    rm[n][2] = nowx;
    rm[n][3] = nowy;
    for (long long i = n - 1; i >= 0; i--) {
      if (s[i] == 'D') {
        nowx--;
      } else if (s[i] == 'S') {
        nowy++;
      } else if (s[i] == 'A') {
        nowx++;
      } else {
        nowy--;
      }
      rm[i][0] = max(rm[i + 1][0], nowx);
      rm[i][1] = min(rm[i + 1][1], nowy);
      rm[i][2] = min(rm[i + 1][2], nowx);
      rm[i][3] = max(rm[i + 1][3], nowy);
    }
    for (long long i = (0); i < (n); i++) {
      if (s[i] == 'D') {
        nowx++;
      } else if (s[i] == 'S') {
        nowy--;
      } else if (s[i] == 'A') {
        nowx--;
      } else {
        nowy++;
      }
      if (rui[n][0] - rui[i + 1][0] > 0) {
        if (rm[i + 1][2] > rui[i + 1][2]) ans = min(ans, X * Y - Y);
      }
      if (rui[n][1] - rui[i + 1][1] < 0) {
        if (rm[i + 1][3] < rui[i + 1][3]) ans = min(ans, X * Y - X);
      }
      if (rui[n][2] - rui[i + 1][2] < 0) {
        if (rm[i + 1][0] < rui[i + 1][0]) ans = min(ans, X * Y - Y);
      }
      if (rui[n][3] - rui[i + 1][3] > 0) {
        if (rm[i + 1][1] > rui[i + 1][1]) ans = min(ans, X * Y - X);
      }
    }
    cout << ans << '\n';
  }
}
