import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author svilen.marchev@gmail.com
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskC solver = new TaskC();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskC {
    static final int[][] OFFSETS = new int[][]{
        // Offsets for row, column. (0,0) is the top left corner.
        new int[]{-1, 0}, // W
        new int[]{+1, 0}, // S
        new int[]{0, -1}, // A
        new int[]{0, +1}, // D
    };

    int[] offsetForMove(char c) {
      switch (c) {
        case 'W':
          return OFFSETS[0];
        case 'S':
          return OFFSETS[1];
        case 'A':
          return OFFSETS[2];
        case 'D':
          return OFFSETS[3];
        default:
          throw new AssertionError();
      }
    }

    char reversePathMove(char c) {
      switch (c) {
        case 'W':
          return 'S';
        case 'S':
          return 'W';
        case 'A':
          return 'D';
        case 'D':
          return 'A';
        default:
          throw new AssertionError();
      }
    }

    long adaptToReduceArea(TaskC.Box reducedBox, TaskC.Point startingPoint, String path) {
      if (!reducedBox.contains(startingPoint)) {
        return Long.MAX_VALUE;
      }
      TaskC.Point point = startingPoint;
      TaskC.Box box = new TaskC.Box(point, point);

      boolean hasCorrected = false;
      for (int i = 0; i < path.length(); ++i) {
        int[] off = offsetForMove(path.charAt(i));
        TaskC.Point newPoint = new TaskC.Point(point.r + off[0], point.c + off[1]);
        if (!hasCorrected && !reducedBox.contains(newPoint)) {
          hasCorrected = true;
          // Push an immediate contra-move of this move, so that we stay in the reduced box.
          // We do this simply by ignoring this move, but we need to update the box to
          // account for the extra move.
          int[] contraOff = offsetForMove(reversePathMove(path.charAt(i)));
          TaskC.Point contraPoint = new TaskC.Point(point.r + contraOff[0], point.c + contraOff[1]);
          box = box.copyUpdate(contraPoint);
        } else {
          point = newPoint;
          box = box.copyUpdate(point);
        }
      }

      return box.area();
    }

    long calcMinReducedArea(String path) {
      TaskC.Point startingPoint = new TaskC.Point(0, 0);

      TaskC.Point point = startingPoint;
      TaskC.Box box = new TaskC.Box(point, point);
      for (int i = 0; i < path.length(); ++i) {
        int[] off = offsetForMove(path.charAt(i));
        point = new TaskC.Point(point.r + off[0], point.c + off[1]);
        box = box.copyUpdate(point);
      }
//    System.out.println(box);
//    System.out.println(box.area());

      long minArea = box.area();

      TaskC.Box withoutFirstCol = new TaskC.Box(new TaskC.Point(box.tl.r, box.tl.c + 1), box.br);
      minArea = Math.min(minArea, adaptToReduceArea(withoutFirstCol, startingPoint, path));

      TaskC.Box withoutFirstRow = new TaskC.Box(new TaskC.Point(box.tl.r + 1, box.tl.c), box.br);
      minArea = Math.min(minArea, adaptToReduceArea(withoutFirstRow, startingPoint, path));

      TaskC.Box withoutLastRow = new TaskC.Box(box.tl, new TaskC.Point(box.br.r - 1, box.br.c));
      minArea = Math.min(minArea, adaptToReduceArea(withoutLastRow, startingPoint, path));

      TaskC.Box withoutLastCol = new TaskC.Box(box.tl, new TaskC.Point(box.br.r, box.br.c - 1));
      minArea = Math.min(minArea, adaptToReduceArea(withoutLastCol, startingPoint, path));

      return minArea;
    }

    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int tests = in.readInt();
      for (int test = 0; test < tests; ++test) {
        String path = in.readString();
        out.println(calcMinReducedArea(path));
      }
    }

    static class Point {
      final int r;
      final int c;

      Point(int r, int c) {
        this.r = r;
        this.c = c;
      }

      public String toString() {
        return String.format("(%d,%d)", r, c);
      }

    }

    static class Box {
      final TaskC.Point tl;
      final TaskC.Point br;

      Box(TaskC.Point tl, TaskC.Point br) {
        this.tl = tl;
        this.br = br;
      }

      long area() {
        return ((long) br.r - tl.r + 1) * (br.c - tl.c + 1);
      }

      boolean contains(TaskC.Point point) {
        return tl.r <= point.r && point.r <= br.r &&
            tl.c <= point.c && point.c <= br.c;
      }

      TaskC.Box copyUpdate(TaskC.Point point) {
        return new TaskC.Box(
            new TaskC.Point(Math.min(tl.r, point.r), Math.min(tl.c, point.c)),
            new TaskC.Point(Math.max(br.r, point.r), Math.max(br.c, point.c)));
      }

      public String toString() {
        return String.format("%s-%s", tl, br);
      }

    }

  }

  static class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int read() {
      if (numChars == -1) {
        throw new InputMismatchException();
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar++];
    }

    public int readInt() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      int res = 0;
      do {
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res *= 10;
        res += c - '0';
        c = read();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public String readString() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      StringBuilder res = new StringBuilder();
      do {
        if (Character.isValidCodePoint(c)) {
          res.appendCodePoint(c);
        }
        c = read();
      } while (!isSpaceChar(c));
      return res.toString();
    }

    public boolean isSpaceChar(int c) {
      if (filter != null) {
        return filter.isSpaceChar(c);
      }
      return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
      public boolean isSpaceChar(int ch);

    }

  }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author svilen.marchev@gmail.com
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskC solver = new TaskC();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskC {
    static final int[][] OFFSETS = new int[][]{
        // Offsets for row, column. (0,0) is the top left corner.
        new int[]{-1, 0}, // W
        new int[]{+1, 0}, // S
        new int[]{0, -1}, // A
        new int[]{0, +1}, // D
    };

    int[] offsetForMove(char c) {
      switch (c) {
        case 'W':
          return OFFSETS[0];
        case 'S':
          return OFFSETS[1];
        case 'A':
          return OFFSETS[2];
        case 'D':
          return OFFSETS[3];
        default:
          throw new AssertionError();
      }
    }

    char reversePathMove(char c) {
      switch (c) {
        case 'W':
          return 'S';
        case 'S':
          return 'W';
        case 'A':
          return 'D';
        case 'D':
          return 'A';
        default:
          throw new AssertionError();
      }
    }

    String reversePath(String s) {
      StringBuilder sb = new StringBuilder(s);
      sb.reverse();
      for (int i = 0; i < sb.length(); ++i) {
        sb.setCharAt(i, reversePathMove(sb.charAt(i)));
      }
      return sb.toString();
    }

    long tryToAdaptToFit(TaskC.Box reducedBox, TaskC.Point startingPoint, String path) {
      TaskC.Point point = startingPoint;
      TaskC.Box box = new TaskC.Box(point, point);
      if (!reducedBox.contains(point)) {
        return -1;
      }

      boolean hasCorrected = false;
      for (int i = 0; i < path.length(); ++i) {
        int[] off = offsetForMove(path.charAt(i));
        TaskC.Point newPoint = new TaskC.Point(point.r + off[0], point.c + off[1]);
        if (!hasCorrected && !reducedBox.contains(newPoint)) {
          hasCorrected = true;
          // Push an immediate contra-move of this move, so that we stay in the reduced box.
          // We do this simply by ignoring this move, but we need to update the box to
          // account for the extra move.
          int[] contraOff = offsetForMove(reversePathMove(path.charAt(i)));
          TaskC.Point contraPoint = new TaskC.Point(point.r + contraOff[0], point.c + contraOff[1]);
          box = TaskC.Box.copyUpdate(box, contraPoint);
        } else {
          point = newPoint;
          box = TaskC.Box.copyUpdate(box, point);
        }
      }

      return box.area();
    }

    long calcMinReducedArea(String path) {
      // boxFromMove[0] - the bounding box of the whole path, including the point before
      // following any move.
      // boxFromMove[i] - the bounding box from the (i-1)th move on, with the (i-1)th move
      // already done.
      TaskC.Box[] boxFromMove = new TaskC.Box[path.length() + 1];

      String reversedPath = reversePath(path);

      TaskC.Point point = new TaskC.Point(0, 0);
      TaskC.Box box = new TaskC.Box(point, point);
      boxFromMove[path.length()] = box;

      for (int i = 0; i < reversedPath.length(); ++i) {
        int[] off = offsetForMove(reversedPath.charAt(i));
        point = new TaskC.Point(point.r + off[0], point.c + off[1]);
        box = TaskC.Box.copyUpdate(box, point);
        boxFromMove[path.length() - 1 - i] = box;
      }

//    System.out.println(box);
//    System.out.println(box.area());

      TaskC.Box wholeBox = box;
      TaskC.Point startingPoint = point;

      long minArea = wholeBox.area();

      {
        TaskC.Box withoutFirstCol = new TaskC.Box(new TaskC.Point(wholeBox.tl.r, wholeBox.tl.c + 1),
            wholeBox.br);
        long area = tryToAdaptToFit(withoutFirstCol, startingPoint, path);
//      System.out.println("area=" + area);
        if (area != -1) {
          minArea = Math.min(minArea, area);
        }
      }

      {
        TaskC.Box withoutFirstRow = new TaskC.Box(new TaskC.Point(wholeBox.tl.r + 1, wholeBox.tl.c),
            wholeBox.br);
        long area = tryToAdaptToFit(withoutFirstRow, startingPoint, path);
        if (area != -1) {
          minArea = Math.min(minArea, area);
        }
      }

      {
        TaskC.Box withoutLastRow = new TaskC.Box(wholeBox.tl,
            new TaskC.Point(wholeBox.br.r - 1, wholeBox.br.c));
        long area = tryToAdaptToFit(withoutLastRow, startingPoint, path);
        if (area != -1) {
          minArea = Math.min(minArea, area);
        }
      }

      {
        TaskC.Box withoutLastCol = new TaskC.Box(wholeBox.tl,
            new TaskC.Point(wholeBox.br.r, wholeBox.br.c - 1));
        long area = tryToAdaptToFit(withoutLastCol, startingPoint, path);
        if (area != -1) {
          minArea = Math.min(minArea, area);
        }
      }

      return minArea;
    }

    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int tests = in.readInt();
      for (int test = 0; test < tests; ++test) {
        String path = in.readString();
        out.println(calcMinReducedArea(path));
      }
    }

    static class Point {
      final int r;
      final int c;

      Point(int r, int c) {
        this.r = r;
        this.c = c;
      }

      public String toString() {
        return String.format("(%d,%d)", r, c);
      }

    }

    static class Box {
      final TaskC.Point tl;
      final TaskC.Point br;

      Box(TaskC.Point tl, TaskC.Point br) {
        this.tl = tl;
        this.br = br;
      }

      long area() {
        return ((long) br.r - tl.r + 1) * (br.c - tl.c + 1);
      }

      public String toString() {
        return String.format("%s-%s", tl, br);
      }

      boolean contains(TaskC.Point point) {
        return tl.r <= point.r && point.r <= br.r &&
            tl.c <= point.c && point.c <= br.c;
      }

      static TaskC.Box copyUpdate(TaskC.Box existing, TaskC.Point point) {
        return new TaskC.Box(
            new TaskC.Point(Math.min(existing.tl.r, point.r), Math.min(existing.tl.c, point.c)),
            new TaskC.Point(Math.max(existing.br.r, point.r), Math.max(existing.br.c, point.c)));
      }

    }

  }

  static class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int read() {
      if (numChars == -1) {
        throw new InputMismatchException();
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar++];
    }

    public int readInt() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      int res = 0;
      do {
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res *= 10;
        res += c - '0';
        c = read();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public String readString() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      StringBuilder res = new StringBuilder();
      do {
        if (Character.isValidCodePoint(c)) {
          res.appendCodePoint(c);
        }
        c = read();
      } while (!isSpaceChar(c));
      return res.toString();
    }

    public boolean isSpaceChar(int c) {
      if (filter != null) {
        return filter.isSpaceChar(c);
      }
      return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
      public boolean isSpaceChar(int ch);

    }

  }
}


#include <bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
#define REP(i , n) for(Long i = 0; i < (Long)n ; i++)
#define pb push_back

using namespace std;

typedef long long Long;

void f(char c, Long &up , Long &right){
	if(c == 'W') {
		up++;
		return;
	}
	if(c == 'S') {
		up--;
		return;
	}
	if(c == 'A' ){
		right--;
		return;
	}
	right++;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	Long T;
	cin >> T;
	REP(t, T){
		string s;
		cin >> s;
		vector<Long> maxi(4 , 0);;
		Long up = 0, right = 0;

		REP(i , s.size()){
			f(s[i] , up , right);
			if(up > 0){
				maxi[0] = max(maxi[0] , up);
			} else {
				maxi[1] = max(maxi[1] , -up);
			}
			if(right > 0){
				maxi[2] = max(maxi[2] , right);
			} else {
				maxi[3] = max(maxi[3] , -right);
			}
		}

		Long area = (maxi[0] + maxi[1] + 1) * (maxi[2] + maxi[3] + 1);

		REP(i , 4){
			if( maxi[i] > 1){
				maxi[i]--;
				area = min(area , (maxi[0] + maxi[1] + 1) * (maxi[2] + maxi[3] + 1) );
				maxi[i]++;
			}
		}
		if(maxi[0] == 1 && maxi[1] == 1){
			up = 0;
			Long maxUp = 0;
			REP(i , s.size()){
				f(s[i] , up , right);
				if(up == 1){
					up--;
				}
				maxUp = max(maxUp, up);
			}
			if(maxUp == 0){
				area = min(area , 2 * (maxi[2] + maxi[3] + 1));
			}
			up = 0;
			maxUp = 0;
			REP(i , s.size()){
				f(s[i] , up , right);
				if(up == -1){
					up++;
				}
				maxUp = max(maxUp, -up);
			}
			if(maxUp == 0){
				area = min(area , 2 * (maxi[2] + maxi[3] + 1));
			}
		}
		if(maxi[2] == 1 && maxi[3] == 1){
			right = 0;
			Long maxRight = 0;
			REP(i , s.size()){
				f(s[i] , up , right);
				if(right == 1){
					right--;
				}
				maxRight = max(maxRight, right);
			}
			if(maxRight == 0){
				area = min(area , 2 * (maxi[0] + maxi[1] + 1));
			}
			right = 0;
			maxRight = 0;
			REP(i , s.size()){
				f(s[i] , up , right);
				if(right == -1){
					right++;
				}
				maxRight = max(maxRight, -right);
			}
			if(maxRight == 0){
				area = min(area , 2 * (maxi[0] + maxi[1] + 1));
			}
		}
		cout << area << endl;

	}

	return 0;
}


#include <bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
#define REP(i , n) for(Long i = 0; i < (Long)n ; i++)
#define pb push_back

using namespace std;

typedef long long Long;

void f(char c, Long &up , Long &right){
	if(c == 'W') {
		up++;
		return;
	}
	if(c == 'S') {
		up--;
		return;
	}
	if(c == 'A' ){
		right--;
		return;
	}
	right++;
}

void actualizar(vector<Long> &maxi , Long up ,Long right){
	if(up > 0){
		maxi[0] = max(maxi[0] , up);
	} else {
		maxi[1] = max(maxi[1] , -up);
	}
	if(right > 0){
		maxi[2] = max(maxi[2] , right);
	} else {
		maxi[3] = max(maxi[3] , -right);
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	Long T;
	cin >> T;
	REP(t, T){
		string s;
		cin >> s;
		vector<Long> maxi(4 , 0);
		Long up = 0, right = 0;

		REP(i , s.size()){
			f(s[i] , up , right);
			actualizar(maxi, up , right);
		}
		Long area = (maxi[0] + maxi[1] + 1) * (maxi[2] + maxi[3] + 1);

		up = 0, right = 0;
		vector<Long> newMaxi(4 , 0);
		bool used = false;
		REP(i , s.size()){
			f(s[i] , up , right);
			if(up == maxi[0] && !used){
				up--;
				actualizar(newMaxi , up - 1 , right);
				used = true;
			}
			actualizar(newMaxi , up  , right);
		}
		area = min(area , (newMaxi[0] + newMaxi[1] + 1) * (newMaxi[2] + newMaxi[3] + 1) );

		up = 0, right = 0;
		newMaxi = vector<Long>(4 , 0);
		used = false;
		REP(i , s.size()){
			f(s[i] , up , right);
			if(-up == maxi[1] && !used){
				up++;
				actualizar(newMaxi , up + 1 , right);
				used = true;
			}
			actualizar(newMaxi , up  , right);
		}
		area = min(area , (newMaxi[0] + newMaxi[1] + 1) * (newMaxi[2] + newMaxi[3] + 1) );

		up = 0, right = 0;
		newMaxi = vector<Long>(4 , 0);
		used = false;
		REP(i , s.size()){
			f(s[i] , up , right);
			if(right == maxi[2] && !used){
				right--;
				actualizar(newMaxi , up  , right - 1);
				used = true;
			}
			actualizar(newMaxi , up  , right );
		}
		area = min(area , (newMaxi[0] + newMaxi[1] + 1) * (newMaxi[2] + newMaxi[3] + 1) );

		up = 0, right = 0;
		newMaxi = vector<Long>(4 , 0);
		used = false;
		REP(i , s.size()){
			f(s[i] , up , right);
			if(-right == maxi[3] && !used){
				right++;
				actualizar(newMaxi , up  , right + 1);
				used = true;
			}
			actualizar(newMaxi , up  , right );
		}

		area = min(area , (newMaxi[0] + newMaxi[1] + 1) * (newMaxi[2] + newMaxi[3] + 1) );
		cout << area << endl;

	}

	return 0;
}


#pragma 03
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>

using namespace std ;

typedef vector<int> vi ;
typedef vector<vi> vii ;
typedef pair<int,int> ii ;
typedef long long ll ;
#define fi first
#define se second
#define rep(i,a,n) for(int i = a ; i <= n ; i++ )
#define Rep(i,a,n) for(int i = a ; i >= n ; i-- )
#define mem(a,n) memset(n,a,sizeof n)
#define sz(n) n.size()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
const int mod = 1e9+7 ;
const int N = 2e5+5 ;

int n,m,k ;
vector<vi> G ;

int main(){
	int t ;
	string s;
	fastio ;
	cin >> t ;
	while(t--) {
		cin >> s ;
		n = s.size() ;
		ll cw = 0 , mw = 0 , ms = 0 , sw = 0 , ss = 0 , cd = 0 , md = 0 , ma = 0 , sd = 0 , sa = 0 ;
		rep(i,0,n-1) {
			if ( s[i] == 'W' ) cw++;
			if ( s[i] == 'S' ) cw--;
			if ( s[i] == 'D' ) cd++;
			if ( s[i] == 'A' ) cd--;
			mw = max(mw,cw) ;
			ms = min(ms,cw) ;
			md = max(md,cd) ;
			ma = min(ma,cd) ;
			sw = max(sw,cw-ms) ;
			ss = max(ss,mw-cw) ;
			sd = max(sd,cd-ma) ;
			sa = max(sa,md-cd) ;
		}
		ll x[2] , y[2] ;
		x[0] = max(ss,sw) ;
		x[1] = max( ll(sw or ss),x[0] - !(ss==sw) ) ;
		y[0] = max(sd,sa) ;
		y[1] = max( ll(sd or sa),y[0] - !(sd==sa) ) ;
		x[0]++ ;
		y[0]++ ;
		x[1]++;
		y[1]++;
		cout << min(x[0]*y[1],x[1]*y[0]) << endl ;
	}
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 240000;
char s[maxn];
int main() {
	int T;
	for(cin >> T; T; T -= 1) {
		cin >> s;
		int cw = 0, cd = 0;
		int ma = 0, md = 0, mw = 0, ms = 0;
		int sa = 0, sd = 0, sw = 0, ss = 0;
		for(int i = 0; s[i]; i += 1) {
			if(s[i] == 'W') cw += 1;
			if(s[i] == 'S') cw -= 1;
			if(s[i] == 'D') cd += 1;
			if(s[i] == 'A') cd -= 1;
			mw = max(mw, cw);
			ms = min(ms, cw);
			md = max(md, cd);
			ma = min(ma, cd);
			sw = max(sw, cw - ms);
			ss = max(ss, mw - cw);
			sd = max(sd, cd - ma);
			sa = max(sa, md - cd);
		}
		ll x[2], y[2];
		x[0] = max(sw, ss);
		x[1] = max(ll(sw or ss), x[0] - !(sw == ss));
		x[1] = max(ll(0),x[0]-!(sw==ss)) ;
 		y[0] = max(sd, sa);
		y[1] = max(ll(sd or sa), y[0] - !(sd == sa));
		ll ans = min((x[0] + 1) * (y[1] + 1), (x[1] + 1) * (y[0] + 1));
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 240000;
char s[maxn];
int main() {
	int T;
	for(cin >> T; T; T -= 1) {
		cin >> s;
		int cw = 0, cd = 0;
		int ma = 0, md = 0, mw = 0, ms = 0;
		int sa = 0, sd = 0, sw = 0, ss = 0;
		for(int i = 0; s[i]; i += 1) {
			if(s[i] == 'W') cw += 1;
			if(s[i] == 'S') cw -= 1;
			if(s[i] == 'D') cd += 1;
			if(s[i] == 'A') cd -= 1;
			mw = max(mw, cw);
			ms = min(ms, cw);
			md = max(md, cd);
			ma = min(ma, cd);
			sw = max(sw, cw - ms);
			ss = max(ss, mw - cw);
			sd = max(sd, cd - ma);
			sa = max(sa, md - cd);
		}
		ll x[2], y[2];
		x[0] = max(sw, ss);
		x[1] = max(ll(sw or ss), x[0] - !(sw == ss));
		x[1] = max(0,x[0]-!(sw==ss)) ;
 		y[0] = max(sd, sa);
		y[1] = max(ll(sd or sa), y[0] - !(sd == sa));
		ll ans = min((x[0] + 1) * (y[1] + 1), (x[1] + 1) * (y[0] + 1));
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 240000;
char s[maxn];
int main() {
	int T;
	for(cin >> T; T; T -= 1) {
		cin >> s;
		int cw = 0, cd = 0;
		int ma = 0, md = 0, mw = 0, ms = 0;
		int sa = 0, sd = 0, sw = 0, ss = 0;
		for(int i = 0; s[i]; i += 1) {
			if(s[i] == 'W') cw += 1;
			if(s[i] == 'S') cw -= 1;
			if(s[i] == 'D') cd += 1;
			if(s[i] == 'A') cd -= 1;
			mw = max(mw, cw);
			ms = min(ms, cw);
			md = max(md, cd);
			ma = min(ma, cd);
			sw = max(sw, cw - ms);
			ss = max(ss, mw - cw);
			sd = max(sd, cd - ma);
			sa = max(sa, md - cd);
		}
		ll x[2], y[2];
		x[0] = max(sw, ss);
		x[1] = max(ll(sw or ss), x[0] - !(sw == ss));
		x[1] = max(0,x[0]-!=(sw==ss)) ;
 		y[0] = max(sd, sa);
		y[1] = max(ll(sd or sa), y[0] - !(sd == sa));
		ll ans = min((x[0] + 1) * (y[1] + 1), (x[1] + 1) * (y[0] + 1));
		cout << ans << "\n";
	}
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <unordered_map>
#define mp make_pair
#define mset(a, b) memset(a, b, sizeof(a))
#define _for(i, a, b) for (int i = a; i <= b; i++)
#define for_(i, a, b) for (int i = a; i >= b; i--)
#define INF 1<<30
#define maxn 200005
#define maxm 100000
#define mod (int)(1e9+7)
#define setbit(x, i) x |= (1ll<<i)
#define resetbit(x, i) x &= ~(1ll<<i)
using namespace std;
typedef long long ll;
int T, a[200005][2];
char s[200005];

int main() {
    cin >> T;
    while (T--) {
        scanf("%s", s+1); s[0] = '0';
        int ss = strlen(s)-1;
        int x = 1, y = 1, mx = 1, my = 1, Mx = 1, My = 1;
        _for (i, 1, ss) {
            if (s[i] == 'W') {y++; My = max(y, My);}
            else if (s[i] == 'S') {y--; my = min(y, my);}
            else if (s[i] == 'D') {x++; Mx = max(x, Mx);}
            else {x--; mx = min(x, mx);}
            a[i][0] = Mx-mx+1; a[i][1] = My-my+1;
        }
        a[1][0] = a[1][1] = 1;
        ll xx = Mx-mx+1, yy = My-my+1;
        x = y = mx = my = Mx = My = 1;
        int ox = 0, oy = 0;
        for_ (i, ss, 1) {
            if (s[i] == 'S') {y++; My = max(y, My);}
            else if (s[i] == 'W') {y--; my = min(y, my);}
            else if (s[i] == 'A') {x++; Mx = max(x, Mx);}
            else {x--; mx = min(x, mx);}
            if(Mx-mx+1 != xx && a[i-1][0] != xx) ox = 1;
            if(My-my+1 != yy && a[i-1][1] != yy) oy = 1;
        }
        ll ans;
        if ((!ox && !oy) || xx <= 2 && yy <= 2) ans = xx*yy;
        else if (!ox || xx <= 2) ans = xx*(yy-1);
        else if (!oy || yy <= 2) ans = yy*(xx-1);
        else ans = min((xx-1)*yy, (yy-1)*xx);
        printf("%lld\n", ans);
    }

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <unordered_map>
#define mp make_pair
#define mset(a, b) memset(a, b, sizeof(a))
#define _for(i, a, b) for (int i = a; i <= b; i++)
#define for_(i, a, b) for (int i = a; i >= b; i--)
#define INF 1<<30
#define maxn 200005
#define maxm 100000
#define mod (int)(1e9+7)
#define setbit(x, i) x |= (1ll<<i)
#define resetbit(x, i) x &= ~(1ll<<i)
using namespace std;
typedef long long ll;
int T, a[200005][2];
char s[200005];

int main() {
    cin >> T;
    while (T--) {
        scanf("%s", s+1); s[0] = '0';
        int ss = strlen(s)-1;
        int x = 1, y = 1, mx = 1, my = 1, Mx = 1, My = 1;
        _for (i, 1, ss) {
            if (s[i] == 'W') {y++; My = max(y, My);}
            else if (s[i] == 'S') {y--; my = min(y, my);}
            else if (s[i] == 'D') {x++; Mx = max(x, Mx);}
            else {x--; mx = min(x, mx);}
            a[i][0] = Mx-mx+1; a[i][1] = My-my+1;
        }
        a[0][0] = a[0][1] = 1;
        ll xx = Mx-mx+1, yy = My-my+1;
        x = y = mx = my = Mx = My = 1;
        int ox = 0, oy = 0;
        for_ (i, ss, 1) {
            if (s[i] == 'S') {y++; My = max(y, My);}
            else if (s[i] == 'W') {y--; my = min(y, my);}
            else if (s[i] == 'A') {x++; Mx = max(x, Mx);}
            else {x--; mx = min(x, mx);}
            if(Mx-mx+1 != xx && a[i-1][0] != xx) ox = 1;
            if(My-my+1 != yy && a[i-1][1] != yy) oy = 1;
        }
        ll ans;
        if ((!ox && !oy) || xx <= 2 && yy <= 2) ans = xx*yy;
        else if (!ox || xx <= 2) ans = xx*(yy-1);
        else if (!oy || yy <= 2) ans = yy*(xx-1);
        else ans = min((xx-1)*yy, (yy-1)*xx);
        printf("%lld\n", ans);
    }

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <unordered_map>
#define mp make_pair
#define mset(a, b) memset(a, b, sizeof(a))
#define _for(i, a, b) for (int i = a; i <= b; i++)
#define for_(i, a, b) for (int i = a; i >= b; i--)
#define INF 1<<30
#define maxn 200005
#define maxm 100000
#define mod (int)(1e9+7)
#define setbit(x, i) x |= (1ll<<i)
#define resetbit(x, i) x &= ~(1ll<<i)
using namespace std;
typedef long long ll;
int T, a[200005][2];
char s[200005];

int main() {
    cin >> T;
    while (T--) {
        scanf("%s", s+1); s[0] = '0';
        int ss = strlen(s)-1;
        int x = 1, y = 1, mx = 1, my = 1, Mx = 1, My = 1;
        _for (i, 1, ss) {
            if (s[i] == 'W') {y++; My = max(y, My);}
            else if (s[i] == 'S') {y--; my = min(y, my);}
            else if (s[i] == 'D') {x++; Mx = max(x, Mx);}
            else {x--; mx = min(x, mx);}
            a[i][0] = Mx-mx+1; a[i][1] = My-my+1;
        }
        ll xx = Mx-mx+1, yy = My-my+1;
        mx = my = Mx = My = 1;
        int ox = 0, oy = 0;
        for_ (i, ss, 2) {
            if (s[i] == 'S') {y++; My = max(y, My);}
            else if (s[i] == 'W') {y--; my = min(y, my);}
            else if (s[i] == 'A') {x++; Mx = max(x, Mx);}
            else {x--; mx = min(x, mx);}
            if(Mx-mx+1 != xx && a[i-1][0] != xx) ox = 1;
            if(My-my+1 != yy && a[i-1][0] != yy) oy = 1;
        }
        ll ans;
        if ((!ox && !oy) || xx <= 2 && yy <= 2) ans = xx*yy;
        else if (!ox || xx <= 2) ans = xx*(yy-1);
        else if (!oy || yy <= 2) ans = yy*(xx-1);
        else ans = min((xx-1)*yy, (yy-1)*xx);
        printf("%lld\n", ans);
    }

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <unordered_map>
#define mp make_pair
#define mset(a, b) memset(a, b, sizeof(a))
#define _for(i, a, b) for (int i = a; i <= b; i++)
#define for_(i, a, b) for (int i = a; i >= b; i--)
#define INF 1<<30
#define maxn 200005
#define maxm 100000
#define mod (int)(1e9+7)
#define setbit(x, i) x |= (1ll<<i)
#define resetbit(x, i) x &= ~(1ll<<i)
using namespace std;
typedef long long ll;
int T;
char s[200005];

int main() {
    cin >> T;
    while (T--) {
        scanf("%s", s+1); s[0] = '0';
        int ss = strlen(s)-1;
        int x = 1, y = 1, mx = 1, my = 1, Mx = 1, My = 1;
        _for (i, 1, ss) {
            if (s[i] == 'W') {y++; My = max(y, My);}
            else if (s[i] == 'S') {y--; my = min(y, my);}
            else if (s[i] == 'D') {x++; Mx = max(x, Mx);}
            else {x--; mx = min(x, mx);}
        }
        ll xx = Mx-mx+1, yy = My-my+1;
        ll ans = min((xx-1)*yy, (yy-1)*xx);
        if (xx <= 2 && yy <= 2) ans = xx*yy;
        else if (xx <= 2) ans = xx*(yy-1);
        else if (yy <= 2) ans = yy*(xx-1);
        printf("%lld\n", ans);
    }

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <unordered_map>
#define mp make_pair
#define mset(a, b) memset(a, b, sizeof(a))
#define _for(i, a, b) for (int i = a; i <= b; i++)
#define for_(i, a, b) for (int i = a; i >= b; i--)
#define INF 1<<30
#define maxn 200005
#define maxm 100000
#define mod (int)(1e9+7)
#define setbit(x, i) x |= (1ll<<i)
#define resetbit(x, i) x &= ~(1ll<<i)
using namespace std;
typedef long long ll;
int T, a[200005][2];
char s[200005];

int main() {
    cin >> T;
    while (T--) {
        scanf("%s", s+1); s[0] = '0';
        int ss = strlen(s)-1;
        int x = 1, y = 1, mx = 1, my = 1, Mx = 1, My = 1;
        _for (i, 1, ss) {
            if (s[i] == 'W') {y++; My = max(y, My);}
            else if (s[i] == 'S') {y--; my = min(y, my);}
            else if (s[i] == 'D') {x++; Mx = max(x, Mx);}
            else {x--; mx = min(x, mx);}
            a[i][0] = Mx-mx+1; a[i][1] = My-my+1;
        }
        a[1][0] = a[1][1] = 1;
        ll xx = Mx-mx+1, yy = My-my+1;
        mx = my = Mx = My = 1;
        int ox = 0, oy = 0;
        for_ (i, ss, 3) {
            if (s[i] == 'S') {y++; My = max(y, My);}
            else if (s[i] == 'W') {y--; my = min(y, my);}
            else if (s[i] == 'A') {x++; Mx = max(x, Mx);}
            else {x--; mx = min(x, mx);}
            if(Mx-mx+1 != xx && a[i-3][0] != xx) ox = 1;
            if(My-my+1 != yy && a[i-3][0] != yy) oy = 1;
        }
        ll ans;
        if ((!ox && !oy) || xx <= 2 && yy <= 2) ans = xx*yy;
        else if (!ox || xx <= 2) ans = xx*(yy-1);
        else if (!oy || yy <= 2) ans = yy*(xx-1);
        else ans = min((xx-1)*yy, (yy-1)*xx);
        printf("%lld\n", ans);
    }

    return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <unordered_map>
#define mp make_pair
#define mset(a, b) memset(a, b, sizeof(a))
#define _for(i, a, b) for (int i = a; i <= b; i++)
#define for_(i, a, b) for (int i = a; i >= b; i--)
#define INF 1<<30
#define maxn 200005
#define maxm 100000
#define mod (int)(1e9+7)
#define setbit(x, i) x |= (1ll<<i)
#define resetbit(x, i) x &= ~(1ll<<i)
using namespace std;
typedef long long ll;
int T, a[200005][2];
char s[200005];

int main() {
    cin >> T;
    while (T--) {
        scanf("%s", s+1); s[0] = '0';
        int ss = strlen(s)-1;
        int x = 1, y = 1, mx = 1, my = 1, Mx = 1, My = 1;
        _for (i, 1, ss) {
            if (s[i] == 'W') {y++; My = max(y, My);}
            else if (s[i] == 'S') {y--; my = min(y, my);}
            else if (s[i] == 'D') {x++; Mx = max(x, Mx);}
            else {x--; mx = min(x, mx);}
            a[i][0] = Mx-mx+1; a[i][1] = My-my+1;
        }
        a[1][0] = a[1][1] = 1;
        ll xx = Mx-mx+1, yy = My-my+1;
        mx = my = Mx = My = 1;
        int ox = 0, oy = 0;
        for_ (i, ss, 1) {
            if (s[i] == 'S') {y++; My = max(y, My);}
            else if (s[i] == 'W') {y--; my = min(y, my);}
            else if (s[i] == 'A') {x++; Mx = max(x, Mx);}
            else {x--; mx = min(x, mx);}
            if(Mx-mx+1 != xx && a[i-1][0] != xx) ox = 1;
            if(My-my+1 != yy && a[i-1][1] != yy) oy = 1;
        }
        ll ans;
        if ((!ox && !oy) || xx <= 2 && yy <= 2) ans = xx*yy;
        else if (!ox || xx <= 2) ans = xx*(yy-1);
        else if (!oy || yy <= 2) ans = yy*(xx-1);
        else ans = min((xx-1)*yy, (yy-1)*xx);
        printf("%lld\n", ans);
    }

    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

int main()
{
	int t;s(t);
	while(t--)
	{
		string str , str1 , str2;
		cin>>str;

		for(int i = 0;i<str.size();i++)
		{
			if(str[i] == 'D') str1.push_back('D');
			else if(str[i] == 'A') str1.push_back('A');
			else if(str[i] == 'S') str2.push_back('S');
			else str2.push_back(str[i]);
		}

		vector<pair<int,int> > da;
		vector<pair<int,int> > ss;

		int curr = 0 , left = 0 , right = 0;
		for(int i = str1.size()-1;i>=0;i--)
		{
			if(str1[i] == 'D')
			{
				right = right + 1;
				left = min(0 , left + 1);
			}
			else
			{
				right = max(0 , right - 1);
				left = left - 1;
			}

			da.push_back(mp(left , right));
		}
		curr = 0;
		int bottom = 0 , top = 0;
		for(int i = str2.size()-1;i>=0;i--)
		{
			if(str2[i] == 'S')
			{
				bottom = bottom-1;
				top = max(0 , top-1);
			}
			else
			{
				bottom = min(0 , bottom + 1);
				top = top + 1;
			}
			ss.push_back(mp(bottom , top));
		}

		reverse(da.begin() , da.end());
		reverse(ss.begin() , ss.end());

		int length = (da.size() == 0 ? 1 : da[0].second - da[0].first + 1);
		int height = (ss.size() == 0 ? 1 : ss[0].second - ss[0].first + 1);
		int ans = (length * height);

//		printf("%d\n" , ans);

		curr = 0 , left = 0 , right = 0;

		for(int i = 0;i<(int)str1.size()-1;i++) //trying to insert D or A
		{
			if(str1[i] == 'D')
			{
				curr++;
			}
			else
			{
				curr--;
			}

			left = min(left , curr);
			right = max(right , curr);

			//if i insert D
			int temp_curr = curr+1 , temp_left = left , temp_right = max(right , curr+1);
			int suff_left = da[i+1].first , suff_right = da[i+1].second;

			temp_left = min(temp_left , suff_left + temp_curr) , temp_right = max(temp_right , suff_right + temp_curr);
			ans = min(ans , (temp_right - temp_left + 1)*height);

			//if i insert A
			temp_curr = curr-1 , temp_left = min(left , curr-1) , temp_right = right;
			temp_left = min(temp_left , suff_left + temp_curr) , temp_right = max(temp_right , suff_right + temp_curr);
			ans = min(ans , (temp_right - temp_left + 1)*height);
		}

		curr = 0 , bottom = 0 , top = 0;

		for(int i = 0;i < (int)str2.size()-1;i++) //trying to insert S or w
		{
			if(str2[i] == 'S')
			{
				curr--;
			}
			else
			{
				curr++;
			}
			bottom = min(bottom , curr);
			top = max(top , curr);

			//if i insert S
			int temp_curr = curr-1 , temp_bottom = min(bottom , curr-1) , temp_top = top;
			int suff_bottom = ss[i+1].first , suff_top = ss[i+1].second;

			temp_bottom = min(temp_bottom , suff_bottom + temp_curr) , temp_top = max(temp_top , suff_top + temp_curr);
			ans = min(ans , (temp_top - temp_bottom + 1)*(length));

			//if i insert A
			temp_curr = curr+1 , temp_bottom = bottom , temp_top = max(top , curr + 1);
			temp_bottom = min(temp_bottom , suff_bottom + temp_curr) , temp_top = max(temp_top , suff_top + temp_curr);
			ans = min(ans , (temp_top - temp_bottom + 1)*(length));
		}

		printf("%d\n" , ans);
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

int main()
{
	int t;s(t);
	while(t--)
	{
		string str , str1 , str2;
		cin>>str;

		for(int i = 0;i<str.size();i++)
		{
			if(str[i] == 'D') str1.push_back('D');
			else if(str[i] == 'A') str1.push_back('A');
			else if(str[i] == 'S') str2.push_back('S');
			else str2.push_back(str[i]);
		}

		vector<pair<int,int>> da;
		vector<pair<int,int>> ss;

		int curr = 0 , left = 0 , right = 0;
		for(int i = str1.size()-1;i>=0;i--)
		{
			if(str1[i] == 'D')
			{
				curr++;
			}
			else
			{
				curr--;
			}
			left = min(left , curr);
			right = max(right , curr);

			da.push_back(mp(left , right));
		}
		curr = 0;
		int bottom = 0 , top = 0;
		for(int i = str2.size()-1;i>=0;i--)
		{
			if(str2[i] == 'S')
			{
				curr--;
			}
			else
			{
				curr++;
			}
			bottom = min(bottom , curr);
			top = max(top , curr);

			ss.push_back(mp(bottom , top));
		}

		reverse(da.begin() , da.end());
		reverse(ss.begin() , ss.end());

		int length = (da.size() == 0 ? 1 : da[0].second - da[0].first + 1);
		int height = (ss.size() == 0 ? 1 : ss[0].second - ss[0].first + 1);
		int ans = (length * height);

//		printf("%d\n" , ans);

		curr = 0 , left = 0 , right = 0;

		for(int i = 0;i<(int)str1.size()-1;i++) //trying to insert D or A
		{
			if(str1[i] == 'D')
			{
				curr++;
			}
			else
			{
				curr--;
			}

			left = min(left , curr);
			right = max(right , curr);

			//if i insert D
			int temp_curr = curr+1 , temp_left = left , temp_right = max(right , curr+1);
			int suff_left = da[i+1].first , suff_right = da[i+1].second;

			temp_left = min(temp_left , suff_left + temp_curr) , temp_right = max(temp_right , suff_right + temp_curr);
			ans = min(ans , (temp_right - temp_left + 1)*height);

			//if i insert A
			temp_curr = curr-1 , temp_left = min(left , curr-1) , temp_right = right;
			temp_left = min(temp_left , suff_left + temp_curr) , temp_right = max(temp_right , suff_right + temp_curr);
			ans = min(ans , (temp_right - temp_left + 1)*height);
		}

		curr = 0 , bottom = 0 , top = 0;

		for(int i = 0;i < (int)str2.size()-1;i++) //trying to insert S or w
		{
			if(str2[i] == 'S')
			{
				curr--;
			}
			else
			{
				curr++;
			}
			bottom = min(bottom , curr);
			top = max(top , curr);

			//if i insert S
			int temp_curr = curr-1 , temp_bottom = min(bottom , curr-1) , temp_top = top;
			int suff_bottom = ss[i+1].first , suff_top = ss[i+1].second;

			temp_bottom = min(temp_bottom , suff_bottom + temp_curr) , temp_top = max(temp_top , suff_top + temp_curr);
			ans = min(ans , (temp_top - temp_bottom + 1)*(length));

			//if i insert A
			temp_curr = curr+1 , temp_bottom = bottom , temp_top = max(top , curr + 1);
			temp_bottom = min(temp_bottom , suff_bottom + temp_curr) , temp_top = max(temp_top , suff_top + temp_curr);
			ans = min(ans , (temp_top - temp_bottom + 1)*(length));
		}

		printf("%d\n" , ans);
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

int main()
{
	int t;s(t);
	while(t--)
	{
		string str , str1 , str2;
		cin>>str;

		for(int i = 0;i<str.size();i++)
		{
			if(str[i] == 'D') str1.push_back('D');
			else if(str[i] == 'A') str1.push_back('A');
			else if(str[i] == 'S') str2.push_back('S');
			else str2.push_back(str[i]);
		}

		vector<pair<int,int> > da;
		vector<pair<int,int> > ss;

		int curr = 0 , left = 0 , right = 0;
		for(int i = str1.size()-1;i>=0;i--)
		{
			if(str1[i] == 'D')
			{
				right = right + 1;
				left = min(0 , left + 1);
			}
			else
			{
				right = max(0 , right - 1);
				left = left - 1;
			}

			da.push_back(mp(left , right));
		}
		curr = 0;
		int bottom = 0 , top = 0;
		for(int i = str2.size()-1;i>=0;i--)
		{
			if(str2[i] == 'S')
			{
				bottom = bottom-1;
				top = max(0 , top-1);
			}
			else
			{
				bottom = min(0 , bottom + 1);
				top = top + 1;
			}
			ss.push_back(mp(bottom , top));
		}

		reverse(da.begin() , da.end());
		reverse(ss.begin() , ss.end());

		int length = (da.size() == 0 ? 1 : da[0].second - da[0].first + 1);
		int height = (ss.size() == 0 ? 1 : ss[0].second - ss[0].first + 1);
		ll ans = (1ll * length * height);

//		printf("%d\n" , ans);

		curr = 0 , left = 0 , right = 0;

		for(int i = 0;i<(int)str1.size()-1;i++) //trying to insert D or A
		{
			if(str1[i] == 'D')
			{
				curr++;
			}
			else
			{
				curr--;
			}

			left = min(left , curr);
			right = max(right , curr);

			//if i insert D
			int temp_curr = curr+1 , temp_left = left , temp_right = max(right , curr+1);
			int suff_left = da[i+1].first , suff_right = da[i+1].second;

			temp_left = min(temp_left , suff_left + temp_curr) , temp_right = max(temp_right , suff_right + temp_curr);
			ans = min(1ll*ans , 1ll * (temp_right - temp_left + 1)*height);

			//if i insert A
			temp_curr = curr-1 , temp_left = min(left , curr-1) , temp_right = right;
			temp_left = min(temp_left , suff_left + temp_curr) , temp_right = max(temp_right , suff_right + temp_curr);
			ans = min(1ll*ans , 1ll * (temp_right - temp_left + 1)*height);
		}

		curr = 0 , bottom = 0 , top = 0;

		for(int i = 0;i < (int)str2.size()-1;i++) //trying to insert S or w
		{
			if(str2[i] == 'S')
			{
				curr--;
			}
			else
			{
				curr++;
			}
			bottom = min(bottom , curr);
			top = max(top , curr);

			//if i insert S
			int temp_curr = curr-1 , temp_bottom = min(bottom , curr-1) , temp_top = top;
			int suff_bottom = ss[i+1].first , suff_top = ss[i+1].second;

			temp_bottom = min(temp_bottom , suff_bottom + temp_curr) , temp_top = max(temp_top , suff_top + temp_curr);
			ans = min(1ll * ans , 1ll * (temp_top - temp_bottom + 1)*(length));

			//if i insert A
			temp_curr = curr+1 , temp_bottom = bottom , temp_top = max(top , curr + 1);
			temp_bottom = min(temp_bottom , suff_bottom + temp_curr) , temp_top = max(temp_top , suff_top + temp_curr);
			ans = min(1ll * ans , 1ll * (temp_top - temp_bottom + 1)*(length));
		}

		printf("%I64d\n" , ans);
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

int main()
{
	int t;s(t);
	while(t--)
	{
		string str , str1 , str2;
		cin>>str;
		int curr_vert = 0 , curr_hori = 0 , bottom = 0, top = 0 , left = 0 , right = 0;
		int d = 0,a = 0;
		for(int i = 0;i<str.size();i++)
		{
			if(str[i] == 'D')
			{
				str1.push_back(str[i]);
				curr_hori++;
			}
			else if(str[i] == 'A')
			{
				str1.push_back(str[i]);
				curr_hori--;
			}
			else if(str[i] == 'S')
			{
				str2.push_back(str[i]);
				curr_vert--;
			}
			else
			{
				str2.push_back(str[i]);
				curr_vert++;
			}

			top = max(top , curr_vert);
			bottom = min(bottom , curr_vert);
			left = min(left , curr_hori);
			right = max(right , curr_hori);

		}

		for(int i = 1;i<str1.size();i++)
		{
			if(str1[i] == str1[i-1])
			{
				d=1;
			}
		}

		for(int i = 1;i<str2.size();i++)
		{
			if(str2[i] == str2[i-1])
			{
				a=1;
			}
		}

		int length = (right - left + 1);
		int height = (top - bottom + 1);

		int ans = length*height;

		if(d)
		{
			ans = min(ans , (length - 1)*height);
		}

		if(a)
		{
			ans = min(ans , length*(height-1));
		}

		printf("%d\n" , ans);
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

int main()
{
	int t;s(t);
	while(t--)
	{
		string str , str1 , str2;
		cin>>str;

		for(int i = 0;i<str.size();i++)
		{
			if(str[i] == 'D') str1.push_back('D');
			else if(str[i] == 'A') str1.push_back('A');
			else if(str[i] == 'S') str2.push_back('S');
			else str2.push_back(str[i]);
		}

		vector<pair<int,int>> da;
		vector<pair<int,int>> ss;

		int curr = 0 , left = 0 , right = 0;
		for(int i = str1.size()-1;i>=0;i--)
		{
			if(str1[i] == 'D')
			{
				curr++;
			}
			else
			{
				curr--;
			}
			left = min(left , curr);
			right = max(right , curr);

			da.push_back(mp(left , right));
		}
		curr = 0;
		int bottom = 0 , top = 0;
		for(int i = str2.size()-1;i>=0;i--)
		{
			if(str2[i] == 'S')
			{
				curr--;
			}
			else
			{
				curr++;
			}
			bottom = min(bottom , curr);
			top = max(top , curr);

			ss.push_back(mp(bottom , top));
		}

		reverse(da.begin() , da.end());
		reverse(ss.begin() , ss.end());

		int length = (da.size() == 0 ? 1 : da[0].second - da[0].first + 1);
		int height = (ss.size() == 0 ? 1 : ss[0].second - ss[0].first + 1);
		int ans = (length * height);

		printf("%d\n" , ans);

		curr = 0 , left = 0 , right = 0;

		for(int i = 0;i<(int)str1.size()-1;i++) //trying to insert D or A
		{
			if(str1[i] == 'D')
			{
				curr++;
			}
			else
			{
				curr--;
			}

			left = min(left , curr);
			right = max(right , curr);

			//if i insert D
			int temp_curr = curr+1 , temp_left = left , temp_right = max(right , curr+1);
			int suff_left = da[i+1].first , suff_right = da[i+1].second;

			temp_left = min(temp_left , suff_left + temp_curr) , temp_right = max(temp_right , suff_right + temp_curr);
			ans = min(ans , (temp_right - temp_left + 1)*height);

			//if i insert A
			temp_curr = curr-1 , temp_left = min(left , curr-1) , temp_right = right;
			temp_left = min(temp_left , suff_left + temp_curr) , temp_right = max(temp_right , suff_right + temp_curr);
			ans = min(ans , (temp_right - temp_left + 1)*height);
		}

		curr = 0 , bottom = 0 , top = 0;

		for(int i = 0;i < (int)str2.size()-1;i++) //trying to insert S or w
		{
			if(str2[i] == 'S')
			{
				curr--;
			}
			else
			{
				curr++;
			}
			bottom = min(bottom , curr);
			top = max(top , curr);

			//if i insert S
			int temp_curr = curr-1 , temp_bottom = min(bottom , curr-1) , temp_top = top;
			int suff_bottom = ss[i+1].first , suff_top = ss[i+1].second;

			temp_bottom = min(temp_bottom , suff_bottom + temp_curr) , temp_top = max(temp_top , suff_top + temp_curr);
			ans = min(ans , (temp_top - temp_bottom + 1)*(length));

			//if i insert A
			temp_curr = curr+1 , temp_bottom = bottom , temp_top = max(top , curr + 1);
			temp_bottom = min(temp_bottom , suff_bottom + temp_curr) , temp_top = max(temp_top , suff_top + temp_curr);
			ans = min(ans , (temp_top - temp_bottom + 1)*(length));
		}

		printf("%d\n" , ans);
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

int main()
{
	int t;s(t);
	while(t--)
	{
		string str , str1 , str2;
		cin>>str;
		int curr_vert = 0 , curr_hori = 0 , bottom = 0, top = 0 , left = 0 , right = 0;
		int d = 0,a = 0;
		for(int i = 0;i<str.size();i++)
		{
			if(str[i] == 'D')
			{
				str1.push_back(str[i]);
				curr_hori++;
			}
			else if(str[i] == 'A')
			{
				str1.push_back(str[i]);
				curr_hori--;
			}
			else if(str[i] == 'S')
			{
				str2.push_back(str[i]);
				curr_vert--;
			}
			else
			{
				str2.push_back(str[i]);
				curr_vert++;
			}

			top = max(top , curr_vert);
			bottom = min(bottom , curr_vert);
			left = min(left , curr_hori);
			right = max(right , curr_hori);

		}

		for(int i = 1;i<str1.size();i++)
		{
			if(str1[i] == str1[i-1])
			{
				d=1;
			}
		}

		for(int i = 1;i<str2.size();i++)
		{
			if(str2[i] == str2[i-1])
			{
				a=1;
			}
		}

		int length = (right - left + 1);
		int height = (top - bottom + 1);

		int ans = length*height;

		if(d)
		{
			if(str2.size() != 0)
				ans = min(ans , (length - 1)*height);
		}

		if(a)
		{
			if(str1.size() != 0)
				ans = min(ans , length*(height-1));
		}

		printf("%d\n" , ans);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int X1, X2, Y1, Y2, t, x, y;
string str;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);

  cin >> t;
  for (int i = 0; i < t; ++i) {
    cin >> str;
    X1 = X2 = x = Y1 = Y2 = y = 0;
    for (auto i : str) {
      if (i == 'W') {
        y++;
      }
      else if (i == 'S') {
        y--;
      }
      else if (i == 'A') {
        x--;
      }
      else {
        x++;
      }
      X1 = min(X1, x);
      X2 = max(X2, x);
      Y1 = min(Y1, y);
      Y2 = max(Y2, y);
    }
    int n = X2 - X1 + 1;
    int m = Y2 - Y1 + 1;
    if (n == 1) {
      cout << max(2, m - 1) << "\n";
    }
    else if (m == 1) {
      cout << max(2, n - 1) << "\n";
    }
    else {
      cout << min(1ll * n * max(2, m - 1), 1ll * max(2, n - 1) * m) << "\n";
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int X1, X2, Y1, Y2, t, x, y, tmnxmn, tmxxmn, tmnxmx, tmxxmx, tmnymn, tmxymn, tmxymx, tmnymx;
string str;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);

  cin >> t;
  for (int i = 0; i < t; ++i) {
    cin >> str;
    X1 = X2 = x = Y1 = Y2 = y = 0;
    for (auto i : str) {
      if (i == 'W') {
        y++;
      }
      else if (i == 'S') {
        y--;
      }
      else if (i == 'A') {
        x--;
      }
      else {
        x++;
      }
      if (x < X1) {
        tmnxmn = tmxxmn = i;
        X1 = x;
      }
      if (x == X1) {
        tmxxmn = i;
      }
      if (x > X2) {
        tmnxmx = tmxxmx = i;
        X2 = x;
      }
      if (x == X2) {
        tmxxmx = i;
      }
      if (y < Y1) {
        tmnymn = tmxymn = i;
        Y1 = y;
      }
      if (y == Y1) {
        tmxymn = i;
      }
      if (y > Y2) {
        tmnymx = tmxymx = i;
        Y2 = y;
      }
      if (y == Y2) {
        tmxymx = i;
      }
    }
    int n = X2 - X1 + 1;
    int m = Y2 - Y1 + 1;
    if (n == 1) {
      cout << max(2, m - 1) << "\n";
    }
    else if (m == 1) {
      cout << max(2, n - 1) << "\n";
    }
    else {
      long long res = 1ll * n * m;
      if (tmxymn < tmnymx || tmnymn > tmxymx) {
        res = min(res, 1ll * max(2, n - 1) * m);
      }
      if (tmxxmn < tmnxmx || tmnxmn > tmxxmx) {
        res = min(res, 1ll * max(2, m - 1) * n);
      }
      cout << res << "\n";
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int X1, X2, Y1, Y2, t, x, y, tmnxmn, tmxxmn, tmnxmx, tmxxmx, tmnymn, tmxymn, tmxymx, tmnymx;
string str;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);

  cin >> t;
  for (int i = 0; i < t; ++i) {
    X1 = X2 = x = Y1 = Y2 = y = 0;
    tmnxmn = tmxxmn = tmnxmx = tmxxmx = tmnymn = tmxymn = tmxymx = tmnymx = -1;
    cin >> str;
    for (int j = 0; j < str.size(); ++j) {
      char i = str[j];
      if (i == 'W') {
        y++;
      }
      else if (i == 'A') {
        x--;
      }
      else if (i == 'S') {
        y--;
      }
      else {
        x++;
      }
      if (x < X1) {
        tmnxmn = j;
        X1 = x;
      }
      if (x == X1) {
        tmxxmn = j;
      }
      if (x > X2) {
        tmnxmx = j;
        X2 = x;
      }
      if (x == X2) {
        tmxxmx = j;
      }
      if (y < Y1) {
        tmnymn = j;
        Y1 = y;
      }
      if (y == Y1) {
        tmxymn = j;
      }
      if (y > Y2) {
        tmnymx = j;
        Y2 = y;
      }
      if (y == Y2) {
        tmxymx = j;
      }
    }
    int n = X2 - X1 + 1;
    int m = Y2 - Y1 + 1;
    if (n == 1) {
      cout << max(2, m - 1) << "\n";
    }
    else if (m == 1) {
      cout << max(2, n - 1) << "\n";
    }
    else {
      long long res = 1ll * n * m;
      if (tmxxmn < tmnxmx || tmnxmn > tmxxmx) {
        res = min(res, 1ll * max(2, n - 1) * m);
      }
      if (tmxymn < tmnymx || tmnymn > tmxymx) {
        res = min(res, 1ll * max(2, m - 1) * n);
      }
      cout << res << "\n";
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int X1, X2, Y1, Y2, t, x, y, tmnxmn, tmxxmn, tmnxmx, tmxxmx, tmnymn, tmxymn, tmxymx, tmnymx;
string str;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);

  cin >> t;
  for (int i = 0; i < t; ++i) {
    X1 = X2 = x = Y1 = Y2 = y = 0;
    tmnxmn = tmxxmn = tmnxmx = tmxxmx = tmnymn = tmxymn = tmxymx = tmnymx = -1;
    cin >> str;
    for (int j = 0; j < str.size(); ++j) {
      char i = str[j];
      if (i == 'W') {
        y++;
      }
      else if (i == 'A') {
        x--;
      }
      else if (i == 'S') {
        y--;
      }
      else {
        x++;
      }
      if (x < X1) {
        tmnxmn = j;
        X1 = x;
      }
      if (x == X1) {
        tmxxmn = j;
      }
      if (x > X2) {
        tmnxmx = j;
        X2 = x;
      }
      if (x == X2) {
        tmxxmx = j;
      }
      if (y < Y1) {
        tmnymn = j;
        Y1 = y;
      }
      if (y == Y1) {
        tmxymn = j;
      }
      if (y > Y2) {
        tmnymx = j;
        Y2 = y;
      }
      if (y == Y2) {
        tmxymx = j;
      }
    }
    int n = X2 - X1 + 1;
    int m = Y2 - Y1 + 1;
      long long res = 1ll * n * m;
      if (tmxxmn < tmnxmx || tmnxmn > tmxxmx) {
        res = min(res, 1ll * max(2, n - 1) * m);
      }
      if (tmxymn < tmnymx || tmnymn > tmxymx) {
        res = min(res, 1ll * max(2, m - 1) * n);
      }
      cout << res << "\n";
  }

  return 0;
}


#define Otto "1202C"
#define maxn 200000
#include<bits/stdc++.h>
using namespace std;
int T;
void init()
{
//    freopen(Otto".inp","r",stdin);
//    freopen(Otto".out","w",stdout);
}
void Time_decreasing()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}
void enter()
{
    cin>>T;
}
void solve()
{
    while(T--)
    {
        string s;
        cin>>s;
        int width=0,length=0;
        int maxxlength=0,minnlength=0,maxxwidth=0,minnwidth=0;
        int smaxxlength=0,sminnlength=0,smaxxwidth=0,sminnwidth=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='W') width++;
            if(s[i]=='S') width--;
            if(s[i]=='A') length--;
            if(s[i]=='D') length++;
            maxxwidth=max(maxxwidth,width);    /// The road up W
            minnwidth=min(minnwidth,width);    /// The road down S
            maxxlength=max(maxxlength,length); /// The road right D
            minnlength=min(minnlength,length); /// The road left A
            smaxxwidth=max(smaxxwidth,width-minnwidth);     /// The times robot goew up W
            sminnwidth=max(sminnwidth,maxxwidth-width);     /// The times robot goes down S
            smaxxlength=max(smaxxlength,length-minnlength); /// The times robot goes right D
            sminnlength=max(sminnlength,maxxlength-length); /// The times robot goes left A
        }
        int res1,res2,res3,res4;
        res1=max(smaxxwidth,sminnwidth); /// The maximum height of the rectangle ( max of W and S )
        res2=max(int(smaxxwidth>0 || sminnwidth>0),res1- (smaxxwidth!=sminnwidth));
        res3=max(smaxxlength,sminnlength); /// The maximum width of the rectangle ( max of D and A )
        res4=max(int(smaxxlength>0 || sminnlength>0),res3- (smaxxlength!=sminnlength));
        //cout<<res1<<" "<<res2<<" "<<res3<<" "<<res4<<endl;
        cout<<(min(1ll*(res1+1)*(res4+1),1ll*(res2+1)*(res3+1)))<<endl;
    }
}
int main()
{
    init();
    Time_decreasing();
    enter();
    solve();
}


#define Otto "1202C"
#define maxn 200000
#include<bits/stdc++.h>
using namespace std;
int T;
void init()
{
//    freopen(Otto".inp","r",stdin);
//    freopen(Otto".out","w",stdout);
}
void Time_decreasing()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}
void enter()
{
    cin>>T;
}
void solve()
{
    while(T--)
    {
        string s;
        cin>>s;
        int width=0,length=0;
        int maxxlength=0,minnlength=0,maxxwidth=0,minnwidth=0;
        int smaxxlength=0,sminnlength=0,smaxxwidth=0,sminnwidth=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='W') width++;
            if(s[i]=='S') width--;
            if(s[i]=='A') length--;
            if(s[i]=='D') length++;
            maxxwidth=max(maxxwidth,width);    /// The road up W
            minnwidth=min(minnwidth,width);    /// The road down S
            maxxlength=max(maxxlength,length); /// The road right D
            minnlength=min(minnlength,length); /// The road left A
            smaxxwidth=max(smaxxwidth,width-minnwidth);     /// The times robot goew up W
            sminnwidth=max(sminnwidth,maxxwidth-width);     /// The times robot goes down S
            smaxxlength=max(smaxxlength,length-minnlength); /// The times robot goes right D
            sminnlength=max(sminnlength,maxxlength-length); /// The times robot goes left A
        }
        int res1,res2,res3,res4;
        res1=max(smaxxwidth,sminnwidth); /// The maximum height of the rectangle ( max of W and S )
        res2=max(int(smaxxwidth || sminnlength),res1- !(smaxxwidth==sminnwidth));
        res3=max(smaxxlength,sminnlength); /// The maximum width of the rectangle ( max of D and A )
        res4=max(int(smaxxlength || sminnlength),res3- !(smaxxlength==sminnlength));
        //cout<<res1<<" "<<res2<<" "<<res3<<" "<<res4<<endl;
        cout<<min((res1+1)*(res4+1),(res2+1)*(res3+1))<<endl;
    }
}
int main()
{
    init();
    Time_decreasing();
    enter();
    solve();
}


/// This code is written By Otto Von Bismarck :)) ///
#define Otto "1202C"
#define maxn 200000
#include<bits/stdc++.h>
using namespace std;
int T;
void init()
{
//    freopen(Otto".inp","r",stdin);
//    freopen(Otto".out","w",stdout);
}
void Time_decreasing()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}
void enter()
{
    cin>>T;
}
void solve()
{
    while(T--)
    {
        string s;
        cin>>s;
        int width=0,length=0;
        int maxxlength=0,minnlength=0,maxxwidth=0,minnwidth=0;
        int smaxxlength=0,sminnlength=0,smaxxwidth=0,sminnwidth=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='W') width++;
            if(s[i]=='S') width--;
            if(s[i]=='A') length--;
            if(s[i]=='D') length++;
            maxxwidth=max(maxxwidth,width);    /// The road up W
            minnwidth=min(minnwidth,width);    /// The road down S
            maxxlength=max(maxxlength,length); /// The road right D
            minnlength=min(minnlength,length); /// The road left A
            smaxxwidth=max(smaxxwidth,width-minnwidth);     /// The times robot goew up W
            sminnwidth=max(sminnwidth,maxxwidth-width);     /// The times robot goes down S
            smaxxlength=max(smaxxlength,length-minnlength); /// The times robot goes right D
            sminnlength=max(sminnlength,maxxlength-length); /// The times robot goes left A
        }
        int res1,res2,res3,res4;
        res1=max(smaxxwidth,sminnwidth); /// The maximum height of the rectangle ( max of W and S )
        res2=max(int(smaxxwidth>0 || sminnwidth>0),res1- (smaxxwidth!=sminnwidth)); /// By using the operator || and !=  we can determine the case
        res3=max(smaxxlength,sminnlength); /// The maximum width of the rectangle ( max of D and A )
        res4=max(int(smaxxlength>0 || sminnlength>0),res3- (smaxxlength!=sminnlength)); /// By using the operator || and !=  we can determine the case
        //cout<<res1<<" "<<res2<<" "<<res3<<" "<<res4<<endl;
        cout<<(min(1ll*(res1+1)*(res4+1),1ll*(res2+1)*(res3+1)))<<endl;
        /// 1ll*(res1+1)*(res4+1) is the area of the rectangle after increasing or decreasing the width 1 ( First Case)
        /// 1ll*(res2+1)*(res3+1) is the area of the rectangle after increasing or decreasing the length 1 (Second Case)
    }
}
int main()
{
    init();
    Time_decreasing();
    enter();
    solve();
}


#define Otto "1202C"
#define maxn 200000
#include<bits/stdc++.h>
using namespace std;
int T;
void init()
{
//    freopen(Otto".inp","r",stdin);
//    freopen(Otto".out","w",stdout);
}
void Time_decreasing()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}
void enter()
{
    cin>>T;
}
void solve()
{
    while(T--)
    {
        string s;
        cin>>s;
        int width=0,length=0;
        int maxxlength=0,minnlength=0,maxxwidth=0,minnwidth=0;
        int smaxxlength=0,sminnlength=0,smaxxwidth=0,sminnwidth=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='W') width++;
            if(s[i]=='S') width--;
            if(s[i]=='A') length--;
            if(s[i]=='D') length++;
            maxxwidth=max(maxxwidth,width);    /// The road up W
            minnwidth=min(minnwidth,width);    /// The road down S
            maxxlength=max(maxxlength,length); /// The road right D
            minnlength=min(minnlength,length); /// The road left A
            smaxxwidth=max(smaxxwidth,width-minnwidth);     /// The times robot goew up W
            sminnwidth=max(sminnwidth,maxxwidth-width);     /// The times robot goes down S
            smaxxlength=max(smaxxlength,length-minnlength); /// The times robot goes right D
            sminnlength=max(sminnlength,maxxlength-length); /// The times robot goes left A
        }
        int res1,res2,res3,res4;
        res1=max(smaxxwidth,sminnwidth); /// The maximum height of the rectangle ( max of W and S )
        res2=max(int(smaxxwidth>0 || sminnlength>0),res1- int(smaxxwidth!=sminnwidth));
        res3=max(smaxxlength,sminnlength); /// The maximum width of the rectangle ( max of D and A )
        res4=max(int(smaxxlength>0 || sminnlength>0),res3- int(smaxxlength!=sminnlength));
        //cout<<res1<<" "<<res2<<" "<<res3<<" "<<res4<<endl;
        cout<<min((res1+1)*(res4+1),(res2+1)*(res3+1))<<endl;
    }
}
int main()
{
    init();
    Time_decreasing();
    enter();
    solve();
}


#define Otto "1202C"
#define maxn 200000
#include<bits/stdc++.h>
using namespace std;
int T;
void init()
{
//    freopen(Otto".inp","r",stdin);
//    freopen(Otto".out","w",stdout);
}
void Time_decreasing()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}
void enter()
{
    cin>>T;
}
void solve()
{
    while(T--)
    {
        string s;
        cin>>s;
        int width=0,length=0;
        int maxxlength=0,minnlength=0,maxxwidth=0,minnwidth=0;
        int smaxxlength=0,sminnlength=0,smaxxwidth=0,sminnwidth=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='W') width++;
            if(s[i]=='S') width--;
            if(s[i]=='A') length--;
            if(s[i]=='D') length++;
            maxxwidth=max(maxxwidth,width);    /// The road up W
            minnwidth=min(minnwidth,width);    /// The road down S
            maxxlength=max(maxxlength,length); /// The road right D
            minnlength=min(minnlength,length); /// The road left A
            smaxxwidth=max(smaxxwidth,width-minnwidth);     /// The times robot goew up W
            sminnwidth=max(sminnwidth,maxxwidth-width);     /// The times robot goes down S
            smaxxlength=max(smaxxlength,length-minnlength); /// The times robot goes right D
            sminnlength=max(sminnlength,maxxlength-length); /// The times robot goes left A
        }
        int res1,res2,res3,res4;
        res1=max(smaxxwidth,sminnwidth); /// The maximum height of the rectangle ( max of W and S )
        res2=max(int(smaxxwidth || sminnwidth>0),res1- (smaxxwidth!=sminnwidth));
        res3=max(smaxxlength,sminnlength); /// The maximum width of the rectangle ( max of D and A )
        res4=max(int(smaxxlength>0 || sminnlength>0),res3- (smaxxlength!=sminnlength));
        //cout<<res1<<" "<<res2<<" "<<res3<<" "<<res4<<endl;
        cout<<min((res1+1)*(res4+1),(res2+1)*(res3+1))<<endl;
    }
}
int main()
{
    init();
    Time_decreasing();
    enter();
    solve();
}


#define Otto "1202C"
#define maxn 200000
#include<bits/stdc++.h>
using namespace std;
int T;
void init()
{
//    freopen(Otto".inp","r",stdin);
//    freopen(Otto".out","w",stdout);
}
void Time_decreasing()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}
void enter()
{
    cin>>T;
}
void solve()
{
    while(T--)
    {
        string s;
        cin>>s;
        int width=0,length=0;
        int maxxlength=0,minnlength=0,maxxwidth=0,minnwidth=0;
        int smaxxlength=0,sminnlength=0,smaxxwidth=0,sminnwidth=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='W') width++;
            if(s[i]=='S') width--;
            if(s[i]=='A') length--;
            if(s[i]=='D') length++;
            maxxwidth=max(maxxwidth,width);    /// The road up W
            minnwidth=min(minnwidth,width);    /// The road down S
            maxxlength=max(maxxlength,length); /// The road right D
            minnlength=min(minnlength,length); /// The road left A
            smaxxwidth=max(smaxxwidth,width-minnwidth);     /// The times robot goew up W
            sminnwidth=max(sminnwidth,maxxwidth-width);     /// The times robot goes down S
            smaxxlength=max(smaxxlength,length-minnlength); /// The times robot goes right D
            sminnlength=max(sminnlength,maxxlength-length); /// The times robot goes left A
        }
        int res1,res2,res3,res4;
        res1=max(smaxxwidth,sminnwidth); /// The maximum height of the rectangle ( max of W and S )
        res2=max(int(smaxxwidth || sminnwidth>0),res1- (smaxxwidth!=sminnwidth));
        res3=max(smaxxlength,sminnlength); /// The maximum width of the rectangle ( max of D and A )
        res4=max(int(smaxxlength>0 || sminnlength>0),res3- (smaxxlength!=sminnlength));
        //cout<<res1<<" "<<res2<<" "<<res3<<" "<<res4<<endl;
        cout<<(min(1ll*(res1+1)*(res4+1),1ll*(res2+1)*(res3+1)))<<endl;
    }
}
int main()
{
    init();
    Time_decreasing();
    enter();
    solve();
}


#define Otto "1202C"
#define maxn 200000
#include<bits/stdc++.h>
using namespace std;
int T;
void init()
{
//    freopen(Otto".inp","r",stdin);
//    freopen(Otto".out","w",stdout);
}
void Time_decreasing()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}
void enter()
{
    cin>>T;
}
void solve()
{
    while(T--)
    {
        string s;
        cin>>s;
        int width=0,length=0;
        int maxxlength=0,minnlength=0,maxxwidth=0,minnwidth=0;
        int smaxxlength=0,sminnlength=0,smaxxwidth=0,sminnwidth=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='W') width++;
            if(s[i]=='S') width--;
            if(s[i]=='A') length--;
            if(s[i]=='D') length++;
            maxxwidth=max(maxxwidth,width);    /// The road up W
            minnwidth=min(minnwidth,width);    /// The road down S
            maxxlength=max(maxxlength,length); /// The road right D
            minnlength=min(minnlength,length); /// The road left A
            smaxxwidth=max(smaxxwidth,width-minnwidth);     /// The times robot goew up W
            sminnwidth=max(sminnwidth,maxxwidth-width);     /// The times robot goes down S
            smaxxlength=max(smaxxlength,length-minnlength); /// The times robot goes right D
            sminnlength=max(sminnlength,maxxlength-length); /// The times robot goes left A
        }
        int res1,res2,res3,res4;
        res1=max(smaxxwidth,sminnwidth); /// The maximum height of the rectangle ( max of W and S )
        res2=max(int(smaxxwidth or sminnlength),res1- !(smaxxwidth==sminnwidth));
        res3=max(smaxxlength,sminnlength); /// The maximum width of the rectangle ( max of D and A )
        res4=max(int(smaxxlength or sminnlength),res3- !(smaxxlength==sminnlength));
        //cout<<res1<<" "<<res2<<" "<<res3<<" "<<res4<<endl;
        cout<<min((res1+1)*(res4+1),(res2+1)*(res3+1))<<endl;
    }
}
int main()
{
    init();
    Time_decreasing();
    enter();
    solve();
}


#define Otto "1202C"
#define maxn 200000
#include<bits/stdc++.h>
using namespace std;
int T;
void init()
{
//    freopen(Otto".inp","r",stdin);
//    freopen(Otto".out","w",stdout);
}
void Time_decreasing()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}
void enter()
{
    cin>>T;
}
void solve()
{
    while(T--)
    {
        string s;
        cin>>s;
        int width=0,length=0;
        int maxxlength=0,minnlength=0,maxxwidth=0,minnwidth=0;
        int smaxxlength=0,sminnlength=0,smaxxwidth=0,sminnwidth=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='W') width++;
            if(s[i]=='S') width--;
            if(s[i]=='A') length--;
            if(s[i]=='D') length++;
            maxxwidth=max(maxxwidth,width);    /// The road up W
            minnwidth=min(minnwidth,width);    /// The road down S
            maxxlength=max(maxxlength,length); /// The road right D
            minnlength=min(minnlength,length); /// The road left A
            smaxxwidth=max(smaxxwidth,width-minnwidth);     /// The times robot goew up W
            sminnwidth=max(sminnwidth,maxxwidth-width);     /// The times robot goes down S
            smaxxlength=max(smaxxlength,length-minnlength); /// The times robot goes right D
            sminnlength=max(sminnlength,maxxlength-length); /// The times robot goes left A
        }
        int res1,res2,res3,res4;
        res1=max(smaxxwidth,sminnwidth); /// The maximum height of the rectangle ( max of W and S )
        res2=max(int(smaxxwidth>0 || sminnwidth>0),res1- (smaxxwidth!=sminnwidth)); /// By using the operator || and !=  we can determine the case
        res3=max(smaxxlength,sminnlength); /// The maximum width of the rectangle ( max of D and A )
        res4=max(int(smaxxlength>0 || sminnlength>0),res3- (smaxxlength!=sminnlength)); /// By using the operator || and !=  we can determine the case
        //cout<<res1<<" "<<res2<<" "<<res3<<" "<<res4<<endl;
        cout<<(min(1ll*(res1+1)*(res4+1),1ll*(res2+1)*(res3+1)))<<endl;
        /// 1ll*(res1+1)*(res4+1) is the area of the rectangle after increasing or decreasing the width 1 ( First Case)
        /// 1ll*(res2+1)*(res3+1) is the area of the rectangle after increasing or decreasing the length 1 (Second Case)
    }
}
int main()
{
    init();
    Time_decreasing();
    enter();
    solve();
}


#define Otto "1202C"
#define maxn 200000
#include<bits/stdc++.h>
using namespace std;
int T;
void init()
{
//    freopen(Otto".inp","r",stdin);
//    freopen(Otto".out","w",stdout);
}
void Time_decreasing()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}
void enter()
{
    cin>>T;
}
void solve()
{
    while(T--)
    {
        string s;
        cin>>s;
        int width=0,length=0;
        int maxxlength=0,minnlength=0,maxxwidth=0,minnwidth=0;
        int smaxxlength=0,sminnlength=0,smaxxwidth=0,sminnwidth=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='W') width++;
            if(s[i]=='S') width--;
            if(s[i]=='A') length--;
            if(s[i]=='D') length++;
            maxxwidth=max(maxxwidth,width);    /// The road up W
            minnwidth=min(minnwidth,width);    /// The road down S
            maxxlength=max(maxxlength,length); /// The road right D
            minnlength=min(minnlength,length); /// The road left A
            smaxxwidth=max(smaxxwidth,width-minnwidth);     /// The times robot goew up W
            sminnwidth=max(sminnwidth,maxxwidth-width);     /// The times robot goes down S
            smaxxlength=max(smaxxlength,length-minnlength); /// The times robot goes right D
            sminnlength=max(sminnlength,maxxlength-length); /// The times robot goes left A
        }
        int res1,res2,res3,res4;
        res1=max(smaxxwidth,sminnwidth); /// The maximum height of the rectangle ( max of W and S )
        res2=max(int(smaxxwidth>0 || sminnlength>0),res1- (smaxxwidth!=sminnwidth));
        res3=max(smaxxlength,sminnlength); /// The maximum width of the rectangle ( max of D and A )
        res4=max(int(smaxxlength>0 || sminnlength>0),res3- (smaxxlength!=sminnlength));
        //cout<<res1<<" "<<res2<<" "<<res3<<" "<<res4<<endl;
        cout<<min((res1+1)*(res4+1),(res2+1)*(res3+1))<<endl;
    }
}
int main()
{
    init();
    Time_decreasing();
    enter();
    solve();
}


#define Otto "1202C"
#define maxn 200000
#include<bits/stdc++.h>
using namespace std;
int T;
void init()
{
//    freopen(Otto".inp","r",stdin);
//    freopen(Otto".out","w",stdout);
}
void Time_decreasing()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}
void enter()
{
    cin>>T;
}
void solve()
{
    while(T--)
    {
        string s;
        cin>>s;
        int width=0,length=0;
        int maxxlength=0,minnlength=0,maxxwidth=0,minnwidth=0;
        int smaxxlength=0,sminnlength=0,smaxxwidth=0,sminnwidth=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='W') width++;
            if(s[i]=='S') width--;
            if(s[i]=='A') length--;
            if(s[i]=='D') length++;
            maxxwidth=max(maxxwidth,width);    /// The road up W
            minnwidth=min(minnwidth,width);    /// The road down S
            maxxlength=max(maxxlength,length); /// The road right D
            minnlength=min(minnlength,length); /// The road left A
            smaxxwidth=max(smaxxwidth,width-minnwidth);     /// The times robot goew up W
            sminnwidth=max(sminnwidth,maxxwidth-width);     /// The times robot goes down S
            smaxxlength=max(smaxxlength,length-minnlength); /// The times robot goes right D
            sminnlength=max(sminnlength,maxxlength-length); /// The times robot goes left A
        }
        int res1,res2,res3,res4;
        res1=max(smaxxwidth,sminnwidth); /// The maximum height of the rectangle ( max of W and S )
        res2=max(int(smaxxwidth<=0 || sminnwidth<=0),res1- (smaxxwidth!=sminnwidth));
        res3=max(smaxxlength,sminnlength); /// The maximum width of the rectangle ( max of D and A )
        res4=max(int(smaxxlength<=0 || sminnlength<=0),res3- (smaxxlength!=sminnlength));
        //cout<<res1<<" "<<res2<<" "<<res3<<" "<<res4<<endl;
        cout<<(min(1ll*(res1+1)*(res4+1),1ll*(res2+1)*(res3+1)))<<endl;
    }
}
int main()
{
    init();
    Time_decreasing();
    enter();
    solve();
}


#define Otto "1202C"
#define maxn 200000
#include<bits/stdc++.h>
using namespace std;
int T;
void init()
{
//    freopen(Otto".inp","r",stdin);
//    freopen(Otto".out","w",stdout);
}
void Time_decreasing()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}
void enter()
{
    cin>>T;
}
void solve()
{
    while(T--)
    {
        string s;
        cin>>s;
        int width=0,length=0;
        int maxxlength=0,minnlength=0,maxxwidth=0,minnwidth=0;
        int smaxxlength=0,sminnlength=0,smaxxwidth=0,sminnwidth=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='W') width++;
            if(s[i]=='S') width--;
            if(s[i]=='A') length--;
            if(s[i]=='D') length++;
            maxxwidth=max(maxxwidth,width);    /// The road up W
            minnwidth=min(minnwidth,width);    /// The road down S
            maxxlength=max(maxxlength,length); /// The road right D
            minnlength=min(minnlength,length); /// The road left A
            smaxxwidth=max(smaxxwidth,width-minnwidth);     /// The times robot goew up W
            sminnwidth=max(sminnwidth,maxxwidth-width);     /// The times robot goes down S
            smaxxlength=max(smaxxlength,length-minnlength); /// The times robot goes right D
            sminnlength=max(sminnlength,maxxlength-length); /// The times robot goes left A
        }
        int res1,res2,res3,res4;
        res1=max(smaxxwidth,sminnwidth); /// The maximum height of the rectangle ( max of W and S )
        res2=max(0,res1- (smaxxwidth!=sminnwidth));
        res3=max(smaxxlength,sminnlength); /// The maximum width of the rectangle ( max of D and A )
        res4=max(0,res3- (smaxxlength!=sminnlength));
        //cout<<res1<<" "<<res2<<" "<<res3<<" "<<res4<<endl;
        cout<<(min(1ll*(res1+1)*(res4+1),1ll*(res2+1)*(res3+1)))<<endl;
    }
}
int main()
{
    init();
    Time_decreasing();
    enter();
    solve();
}


#define Otto "1202C"
#define maxn 200000
#include<bits/stdc++.h>
using namespace std;
int T;
void init()
{
//    freopen(Otto".inp","r",stdin);
//    freopen(Otto".out","w",stdout);
}
void Time_decreasing()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}
void enter()
{
    cin>>T;
}
void solve()
{
    while(T--)
    {
        string s;
        cin>>s;
        int width=0,length=0;
        int maxxlength=0,minnlength=0,maxxwidth=0,minnwidth=0;
        int smaxxlength=0,sminnlength=0,smaxxwidth=0,sminnwidth=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='W') width++;
            if(s[i]=='S') width--;
            if(s[i]=='A') length--;
            if(s[i]=='D') length++;
            maxxwidth=max(maxxwidth,width);    /// The road up W
            minnwidth=min(minnwidth,width);    /// The road down S
            maxxlength=max(maxxlength,length); /// The road right D
            minnlength=min(minnlength,length); /// The road left A
            smaxxwidth=max(smaxxwidth,width-minnwidth);     /// The times robot goew up W
            sminnwidth=max(sminnwidth,maxxwidth-width);     /// The times robot goes down S
            smaxxlength=max(smaxxlength,length-minnlength); /// The times robot goes right D
            sminnlength=max(sminnlength,maxxlength-length); /// The times robot goes left A
        }
        int res1,res2,res3,res4;
        res1=max(smaxxwidth,sminnwidth); /// The maximum height of the rectangle ( max of W and S )
        res2=max(int(smaxxwidth || sminnwidth>0),res1- (smaxxwidth!=sminnwidth));
        res3=max(smaxxlength,sminnlength); /// The maximum width of the rectangle ( max of D and A )
        res4=max(int(smaxxlength>0 || sminnlength>0),res3- (smaxxlength!=sminnlength));
        //cout<<res1<<" "<<res2<<" "<<res3<<" "<<res4<<endl;
        cout<<(long long)(min((res1+1)*(res4+1),(res2+1)*(res3+1)))<<endl;
    }
}
int main()
{
    init();
    Time_decreasing();
    enter();
    solve();
}


#define Otto "1202C"
#define maxn 200000
#include<bits/stdc++.h>
using namespace std;
int T;
void init()
{
//    freopen(Otto".inp","r",stdin);
//    freopen(Otto".out","w",stdout);
}
void Time_decreasing()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}
void enter()
{
    cin>>T;
}
void solve()
{
    while(T--)
    {
        string s;
        cin>>s;
        int width=0,length=0;
        int maxxlength=0,minnlength=0,maxxwidth=0,minnwidth=0;
        int smaxxlength=0,sminnlength=0,smaxxwidth=0,sminnwidth=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='W') width++;
            if(s[i]=='S') width--;
            if(s[i]=='A') length--;
            if(s[i]=='D') length++;
            maxxwidth=max(maxxwidth,width);    /// The road up W
            minnwidth=min(minnwidth,width);    /// The road down S
            maxxlength=max(maxxlength,length); /// The road right D
            minnlength=min(minnlength,length); /// The road left A
            smaxxwidth=max(smaxxwidth,width-minnwidth);     /// The times robot goew up W
            sminnwidth=max(sminnwidth,maxxwidth-width);     /// The times robot goes down S
            smaxxlength=max(smaxxlength,length-minnlength); /// The times robot goes right D
            sminnlength=max(sminnlength,maxxlength-length); /// The times robot goes left A
        }
        int res1,res2,res3,res4;
        res1=max(smaxxwidth,sminnwidth); /// The maximum height of the rectangle ( max of W and S )
        res2=max(smaxxwidth,res1-smaxxwidth);
        res3=max(smaxxlength,sminnlength); /// The maximum width of the rectangle ( max of D and A )
        res4=max(smaxxlength,res3-smaxxlength);
        //cout<<res1<<" "<<res2<<" "<<res3<<" "<<res4<<endl;
        cout<<min((res1+1)*(res4+1),(res2+1)*(res3+1))<<endl;
    }
}
int main()
{
    init();
    Time_decreasing();
    enter();
    solve();
}


#include <bits/stdc++.h>

using namespace std;
#define int64 long long

const int N_MAX = 100010;

int nTest;

void outerInit() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto fi = new ifstream("test.inp");
	if (*fi) {
		cin.rdbuf(fi->rdbuf());
	}
}

void solveData() {
	string S;
	cin >> S;

	int xMin = 0, yMin = 0;
	int xMax = 0, yMax = 0;
	int x = 0, y = 0;
	for (char dir : S) {
		if (dir == 'W') {
			yMax = max(yMax, ++y);
		}

		if (dir == 'S') {
			yMin = min(yMin, --y);
		}

		if (dir == 'D') {
			xMax = max(xMax, ++x);
		}

		if (dir == 'A') {
			xMin = min(xMin, --x);
		}
	}

	int64 dx = xMax - xMin + 1;
	int64 dy = yMax - yMin + 1;
	int64 result = dx * dy;
	if (dx > 2) {
		result = min(result, (dx - 1) * dy);
	}
	if (dy > 2) {
		result = min(result, dx * (dy - 1));
	}
	cout << result;
}

int main() {
	outerInit();

	cin >> nTest;
	for (int i = 1; i <= nTest; ++i) {
		solveData();
		cout << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;
#define int64 long long

const int N_MAX = 100010;

int nTest;

void outerInit() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto fi = new ifstream("test.inp");
	if (*fi) {
		cin.rdbuf(fi->rdbuf());
	}
}

void solveData() {
	string S;
	cin >> S;

	int xMin = 0, yMin = 0;
	int xMax = 0, yMax = 0;
	int x = 0, y = 0;
	for (char dir : S) {
		if (dir == 'W') {
			yMax = max(yMax, ++y);
		}

		if (dir == 'S') {
			yMin = min(yMin, --y);
		}

		if (dir == 'D') {
			xMax = max(xMax, ++x);
		}

		if (dir == 'A') {
			xMin = min(xMin, --x);
		}
	}

	int64 dx = xMax - xMin + 1;
	int64 dy = yMax - yMin + 1;
	int64 result = dx * dy;
	if (dx > 2 && x != 0) {
		result = min(result, (dx - 1) * dy);
	}
	if (dy > 2 && y != 0) {
		result = min(result, dx * (dy - 1));
	}
	cout << result;
}

int main() {
	outerInit();

	cin >> nTest;
	for (int i = 1; i <= nTest; ++i) {
		solveData();
		cout << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;
#define int64 long long

int nTest;

void outerInit() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto fi = new ifstream("test.inp");
	if (*fi) {
		cin.rdbuf(fi->rdbuf());
	}
}

void solveData() {
	string S;
	cin >> S;

	int xMin = 0, yMin = 0;
	int xMax = 0, yMax = 0;
	bool fromBottomX = true, reduceX = false;
	bool fromBottomY = true, reduceY = false;
	int x = 0, y = 0;
	for (char dir : S) {
		if (dir == 'W') {
			++y;
			if (y > yMax) {
				yMax = y;
				fromBottomY = false;
				reduceY = true;
			}
			else if (fromBottomY && y == yMax) {
				reduceY = false;
			}
		}

		if (dir == 'S') {
			--y;
			if (y < yMin) {
				yMin = y;
				fromBottomY = true;
				reduceY = true;
			}
			else if (!fromBottomY && y == yMin) {
				reduceY = false;
			}
		}

		if (dir == 'D') {
			++x;
			if (x > xMax) {
				xMax = x;
				fromBottomX = false;
				reduceX = true;
			}
			else if (fromBottomX && x == xMax) {
				reduceX = false;
			}
		}

		if (dir == 'A') {
			--x;
			if (x < xMin) {
				xMin = x;
				fromBottomX = true;
				reduceX = true;
			}
			else if (!fromBottomX && x == xMin) {
				reduceX = false;
			}
		}
	}

	int64 dx = xMax - xMin + 1;
	int64 dy = yMax - yMin + 1;
	int64 result = dx * dy;
	if (dx > 2 && reduceX) {
		result = min(result, (dx - 1) * dy);
	}
	if (dy > 2 && reduceY) {
		result = min(result, dx * (dy - 1));
	}
	cout << result;
}

int main() {
	outerInit();

	cin >> nTest;
	for (int i = 1; i <= nTest; ++i) {
		solveData();
		cout << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;
#define int64 long long

const int N_MAX = 100010;

int nTest;

void outerInit() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto fi = new ifstream("test.inp");
	if (*fi) {
		cin.rdbuf(fi->rdbuf());
	}
}

void solveData() {
	string S;
	cin >> S;

	int xMin = 0, yMin = 0;
	int xMax = 0, yMax = 0;
	bool reduceX = true;
	bool reduceY = true;
	int x = 0, y = 0;
	for (char dir : S) {
		if (dir == 'W' && yMax < ++y) {
			yMax = y;
			reduceY = true;
		}

		if (dir == 'S' && yMin > --y) {
			yMin = y;
			reduceY = false;
		}

		if (dir == 'D' && xMax < ++x) {
			xMax = x;
			reduceX = true;
		}

		if (dir == 'A' && xMin > --x) {
			xMin = x;
			reduceX = false;
		}
	}

	int64 dx = xMax - xMin + 1;
	int64 dy = yMax - yMin + 1;
	int64 result = dx * dy;
	if (dx > 2 && ((reduceX && x != xMin) || (!reduceX && x != xMax))) {
		result = min(result, (dx - 1) * dy);
	}
	if (dy > 2 && ((reduceY && y != yMin) || (!reduceY && y != yMax))) {
		result = min(result, dx * (dy - 1));
	}
	cout << result;
}

int main() {
	outerInit();

	cin >> nTest;
	for (int i = 1; i <= nTest; ++i) {
		solveData();
		cout << "\n";
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
using namespace std;
int n, i, j, cnta, cntd, cntw, cnts;
string s;
long long w, d, mnd, mnw, mxd, mxw, ans;
main(){
    cin >> n;
    for(i = 1; i<=n; ++i){
        cin >> s;
        w = 0;
        d = 0;
        cntd = 0;
        cntw = 0;
        cnta = 0;
        cnts = 0;
        mxd=0;
        mnd=0;
        mxw=0;
        mnw=0;
        ans = 0;
        for(j= 0; j<s.size(); ++j) {
            if (s[j]=='D') {++d; cntd++;}
            else if (s[j]=='A') {--d; cnta++;}
            else if (s[j]=='S') {++w; cnts++;}
            else if (s[j]=='W') {--w; cntw++;}
            mxd= max(mxd, d);
            mxw= max(mxw, w);

            mnd= min(mnd, d);
            mnw= min(mnw, w);
        }
       // cout << mxw<<" "<<mnw<<" "<<mxd<<" "<<mnd<<" check:";
        long long ln1 =mxd-mnd +1LL;
        long long ln2 = mxw-mnw+1LL;
        ans = ln1*ln2;
        //cout << ln1<<" "<<ln2<<"\n";
        if (cntd!=cnta && (cntd>1 || cnta>1)) ans = min(ans, (mxd-mnd)*(mxw-mnw+1LL));
        if (cntw!=cnts && (cntw>1 || cnts>1 )) ans = min(ans, (mxd-mnd+1LL)*(mxw-mnw));
        cout <<ans<<"\n";
    }
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
using namespace std;
int n, i, j, cnta, cntd, cntw, cnts;
string s;
long long w, d, mnd, mnw, mxd, mxw, ans;
main(){
    cin >> n;
    for(i = 1; i<=n; ++i){
        cin >> s;
        w = 0;
        d = 0;
        cntd = 0;
        cntw = 0;
        cnta = 0;
        cnts = 0;
        mxd=0;
        mnd=0;
        mxw=0;
        mnw=0;
        ans = 0;
        for(j= 0; j<s.size(); ++j) {
            if (s[j]=='D') {++d; cntd++;}
            else if (s[j]=='A') {--d; cnta++;}
            else if (s[j]=='S') {--w; cnts++;}
            else if (s[j]=='W') {++w; cntw++;}
            mxd= max(mxd, d);
            mxw= max(mxw, w);

            mnd= min(mnd, d);
            mnw= min(mnw, w);
        }
       // cout << mxw<<" "<<mnw<<" "<<mxd<<" "<<mnd<<" check:";
        long long ln1 =mxd-mnd +1LL;
        long long ln2 = mxw-mnw+1LL;
        ans = ln1*ln2;
        //cout << ln1<<" "<<ln2<<"\n";
        if (cntd!=cnta ){
                if (abs(cntd-cnta)>1) ans = min(ans, (mxd-mnd)*(mxw-mnw+1LL));
                if (abs(cntd-cnta)==1 && mxd-mnd!=1) ans = min(ans, (mxd-mnd)*(mxw-mnw+1LL));
        }
        if (cntw!=cnts){
               if (abs(cntw-cnts)>1) ans = min(ans, (mxd-mnd+1LL)*(mxw-mnw));
               if (abs(cntw-cnts)==1 && mxw-mnw!=1) ans = min(ans, (mxd-mnd+1LL)*(mxw-mnw));
        }
        cout <<ans<<"\n";
    }
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
using namespace std;
int n, i, j, cnta, cntd, cntw, cnts;
string s;
long long w, d, mnd, mnw, mxd, mxw, ans;
main(){
    cin >> n;
    for(i = 1; i<=n; ++i){
        cin >> s;
        w = 0;
        d = 0;
        cntd = 0;
        cntw = 0;
        cnta = 0;
        cnts = 0;
        mxd=0;
        mnd=0;
        mxw=0;
        mnw=0;
        ans = 0;
        for(j= 0; j<s.size(); ++j) {
            if (s[j]=='D') {++d; cntd++;}
            else if (s[j]=='A') {--d; cnta++;}
            else if (s[j]=='S') {++w; cnts++;}
            else if (s[j]=='W') {--w; cntw++;}
            mxd= max(mxd, d);
            mxw= max(mxw, w);

            mnd= min(mnd, d);
            mnw= min(mnw, w);
        }
       // cout << mxw<<" "<<mnw<<" "<<mxd<<" "<<mnd<<" check:";
        long long ln1 =mxd-mnd +1;
        long long ln2 = mxw-mnw+1;
        ans = ln1*ln2;
        //cout << ln1<<" "<<ln2<<"\n";
        if (ln1>2 && cntd!=cnta) ans = min(ans, (mxd-mnd)*(mxw-mnw+1));
        if (ln2>2 && cntw!=cnts) ans = min(ans, (mxd-mnd+1)*(mxw-mnw));
        cout <<ans<<"\n";
    }
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
using namespace std;
int n, i, j, cnta, cntd, cntw, cnts;
string s;
long long w, d, mnd, mnw, mxd, mxw, ans;
main(){
    cin >> n;
    for(i = 1; i<=n; ++i){
        cin >> s;
        w = 0;
        d = 0;
        cntd = 0;
        cntw = 0;
        cnta = 0;
        cnts = 0;
        mxd=0;
        mnd=0;
        mxw=0;
        mnw=0;
        ans = 0;
        for(j= 0; j<s.size(); ++j) {
            if (s[j]=='D') {++d; cntd++;}
            else if (s[j]=='A') {--d; cnta++;}
            else if (s[j]=='S') {++w; cnts++;}
            else if (s[j]=='W') {--w; cntw++;}
            mxd= max(mxd, d);
            mxw= max(mxw, w);

            mnd= min(mnd, d);
            mnw= min(mxw, w);
        }
      //  cout << mxw<<" "<<mnw<<" "<<mxd<<" "<<mnd<<" check:";
        long long ln1 =mxd-mnd +1;
        long long ln2 = mxw-mnw+1;
        ans = ln1*ln2;
        //cout << ln1<<" "<<ln2<<"\n";
        if (ln1>2 && cntd!=cnta) ans = min(ans, (mxd-mnd)*(mxw-mnw+1));
        if (ln2>2 && cntw!=cnts) ans = min(ans, (mxd-mnd+1)*(mxw-mnw));
        cout <<ans<<"\n";
    }
}