You have a string s — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands:

  * 'W' — move one cell up; 
  * 'S' — move one cell down; 
  * 'A' — move one cell left; 
  * 'D' — move one cell right. 



Let Grid(s) be the grid of minimum possible area such that there is a position in the grid where you can place the robot in such a way that it will not fall from the grid while running the sequence of commands s. For example, if s = DSAWWAW then Grid(s) is the 4 × 3 grid:

  1. you can place the robot in the cell (3, 2); 
  2. the robot performs the command 'D' and moves to (3, 3); 
  3. the robot performs the command 'S' and moves to (4, 3); 
  4. the robot performs the command 'A' and moves to (4, 2); 
  5. the robot performs the command 'W' and moves to (3, 2); 
  6. the robot performs the command 'W' and moves to (2, 2); 
  7. the robot performs the command 'A' and moves to (2, 1); 
  8. the robot performs the command 'W' and moves to (1, 1). 

<image>

You have 4 extra letters: one 'W', one 'A', one 'S', one 'D'. You'd like to insert at most one of these letters in any position of sequence s to minimize the area of Grid(s).

What is the minimum area of Grid(s) you can achieve?

Input

The first line contains one integer T (1 ≤ T ≤ 1000) — the number of queries.

Next T lines contain queries: one per line. This line contains single string s (1 ≤ |s| ≤ 2 ⋅ 10^5, s_i ∈ \{W, A, S, D\}) — the sequence of commands.

It's guaranteed that the total length of s over all queries doesn't exceed 2 ⋅ 10^5.

Output

Print T integers: one per query. For each query print the minimum area of Grid(s) you can achieve.

Example

Input


3
DSAWWAW
D
WA


Output


8
2
4

Note

In the first query you have to get string DSAWW\underline{D}AW.

In second and third queries you can not decrease the area of Grid(s).
import java.util.*;
import java.io.*;

public class Main {
  public static void main(String[] args) {
	  FastScanner sc = new FastScanner();
	  int Q = sc.nextInt();
	  for (int q = 0; q < Q; q++) {
		  String commands = sc.next();
		  int N = commands.length();
		  int[] xPos = new int[N+1];
		  int[] yPos = new int[N+1];
		  int minX = 0;
		  int maxX = 0;
		  int minY = 0;
		  int maxY = 0;
		  for (int i = 0; i < N; i++) {
			  char c = commands.charAt(i);
			  if (c == 'W') {
				  yPos[i+1] = yPos[i] + 1;
				  xPos[i+1] = xPos[i] + 0;
				  maxY = Math.max(maxY,yPos[i+1]);
			  } else if (c == 'S') {
				  yPos[i+1] = yPos[i] - 1;
				  xPos[i+1] = xPos[i] + 0;
				  minY = Math.min(minY,yPos[i+1]);
			  } else if (c == 'A') {
				  yPos[i+1] = yPos[i] + 0;
				  xPos[i+1] = xPos[i] - 1;
				  minX = Math.min(minX,xPos[i+1]);
			  } else {
				  yPos[i+1] = yPos[i] + 0;
				  xPos[i+1] = xPos[i] + 1;
				  maxX = Math.max(maxX,xPos[i+1]);
			  }
		  }		  
		  //Can the size be reduced?
		  int wReduce = 0;
		  int width = maxX - minX + 1;
		  ArrayList<Integer> maxXs = new ArrayList<Integer>();
		  ArrayList<Integer> minXs = new ArrayList<Integer>();
		  for (int i = 0; i <= N; i++) {
			  if (xPos[i] == maxX) {
				  maxXs.add(i);
			  }
			  if (xPos[i] == minX) {
				  minXs.add(i);
			  }
		  }
		  if (width >= 3) {
			  if (maxXs.get(maxXs.size() - 1) < minXs.get(0) || minXs.get(minXs.size() - 1) < maxXs.get(0)) {
				  wReduce = 1;
			  }
		  }
		  
		  int length = maxY - minY + 1;
		  int lReduce = 0;
		  ArrayList<Integer> maxYs = new ArrayList<Integer>();
		  ArrayList<Integer> minYs = new ArrayList<Integer>();
		  for (int i = 0; i <= N; i++) {
			  if (yPos[i] == maxY) {
				  maxYs.add(i);
			  }
			  if (yPos[i] == minY) {
				  minYs.add(i);
			  }
		  }
		  if (length >= 3) {
			  if (maxYs.get(maxYs.size() - 1) < minYs.get(0) || minYs.get(minYs.size() - 1) < maxYs.get(0)) {
				  lReduce = 1;
			  }
		  }
		  long ans1 = ((long)width)*(length-lReduce);
		  long ans2 = ((long)length)*(width-wReduce);
		  System.out.println(Math.min(ans1,ans2));
	  }
  }


  static class FastScanner { 
    BufferedReader br; 
    StringTokenizer st; 
  
    public FastScanner() { 
      br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
  
    String next() { 
      while (st == null || !st.hasMoreElements()) { 
        try
        { 
          st = new StringTokenizer(br.readLine()); 
        } 
        catch (IOException  e) 
        { 
          e.printStackTrace(); 
        } 
      } 
      return st.nextToken(); 
    } 
  
    int nextInt() { 
      return Integer.parseInt(next()); 
    } 
  
    long nextLong() { 
      return Long.parseLong(next()); 
    } 
  
    double nextDouble() { 
      return Double.parseDouble(next()); 
    } 
  
    String nextLine() { 
      String str = ""; 
      try
      { 
        str = br.readLine(); 
      } 
      catch (IOException e) 
      { 
        e.printStackTrace(); 
      } 
      return str; 
    }
  }
}