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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
 
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader sc = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, sc, out);
        out.close();
    }
 
    static class Task {
    	public static final char up='W';
    	public static final char down='S';
    	public static final char left='A';
    	public static final char right='D';
    	
        public void solve(int testNumber, InputReader sc, PrintWriter out) {
            int T=sc.nextInt();
            
            while(T-->0) {
            	char[] res=(" "+sc.next()).toCharArray();
                int x=0;
                int y=0;
                
                
                int n=res.length-1;
                long[] preX=new long[res.length];
                long[] preY=new long[res.length];
                long max_x=0;
                long min_x=0;
                long max_y=0;
                long min_y=0;
                
                for(int i=1;i<=n;i++) {
                	int dx=0;
                	int dy=0;
                	if(res[i]==down||res[i]==up)
                		dx=res[i]==up?1:-1;
                	else
                		dy=res[i]==right?1:-1;
                	preX[i]=preX[i-1]+dx;
                	preY[i]=preY[i-1]+dy;
                	max_x=Math.max(max_x, preX[i]);
                	min_x=Math.min(min_x, preX[i]);
                	max_y=Math.max(max_y, preY[i]);
                	min_y=Math.min(min_y, preY[i]);
                }
                long ans=(max_x-min_x+1)*(max_y-min_y+1);
                if(max_x-min_x+1>2) {
                	Node firstMin=new Node(0,0);
                    Node lastMax=new Node(0,0);
                    Node firstMax=new Node(0,0);
                    Node lastMin=new Node(0,0);
                    for(int i=1;i<=n;i++) {
                        if(preX[i]<firstMin.val) {
                        	firstMin.val=preX[i];
                        	firstMin.index=i;
                        }
                        if(preX[i]>=lastMax.val) {
                        	lastMax.val=preX[i];
                        	lastMax.index=i;
                        }
                        
                        if(preX[i]<=lastMin.val) {
                        	lastMin.val=preX[i];
                        	lastMin.index=i;
                        }
                        if(preX[i]>firstMax.val) {
                        	firstMax.val=preX[i];
                        	firstMax.index=i;
                        }
                    }
                    if(firstMin.index>lastMax.index) {     //+1
                    	ans=Math.min(ans, (max_x-min_x)*(max_y-min_y+1));
                    }
                    if(firstMax.index>lastMin.index) {    //-1
                    	ans=Math.min(ans, (max_x-min_x)*(max_y-min_y+1));
                    }
                }
                if(max_y-min_y+1>2) {
                	Node firstMin=new Node(0,0);
                    Node lastMax=new Node(0,0);
                    Node firstMax=new Node(0,0);
                    Node lastMin=new Node(0,0);
                    for(int i=1;i<=n;i++) {
                        if(preY[i]<firstMin.val) {
                        	firstMin.val=preY[i];
                        	firstMin.index=i;
                        }
                        if(preY[i]>=lastMax.val) {
                        	lastMax.val=preY[i];
                        	lastMax.index=i;
                        }
                        
                        if(preY[i]<=lastMin.val) {
                        	lastMin.val=preY[i];
                        	lastMin.index=i;
                        }
                        if(preY[i]>firstMax.val) {
                        	firstMax.val=preY[i];
                        	firstMax.index=i;
                        }
                    }
                    if(firstMin.index>lastMax.index) {  //+1
                    	ans=Math.min(ans, (max_x-min_x+1)*(max_y-min_y));
                    }
                    if(firstMax.index>lastMin.index) {  //-1
                    	ans=Math.min(ans, (max_x-min_x+1)*(max_y-min_y));
                    }
                }
                out.println(ans);
            }
        }
 
    }
    
    static class Node{
    	int index;
    	long val;
    	
    	public Node(int index,int val) {
    		this.index=index;
    		this.val=val;
    	}
    }
 
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
 
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
 
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
 
        public int nextInt() {
            return Integer.parseInt(next());
        }
 
        public long nextLong() {
            return Long.parseLong(next());
        }
 
    }
}