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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

@SuppressWarnings("unused")
public class Solution{
	
	static final int inf = (int)1e9;
	
	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws IOException {
		FastScanner fs = new FastScanner();
    	PrintWriter out = new PrintWriter(System.out);
    	
    	int tt = fs.nextInt();
    	outer:
    	while(tt-->0) {
    		
    		char[] s = fs.next().toCharArray();
    		int n = s.length;
    		int[][] a = new int[n+1][2];
    		
    		int[][] premax = new int[n+2][2], sufmax = new int[n+2][2], premin = new int[n+2][2], sufmin = new int[n+2][2];
    		for(int j=0;j<2;j++) {
    			premax[0][j] = -inf; premin[0][j] = inf;
    			sufmax[n+1][j] = -inf; sufmin[n+1][j] = inf;
    		}
    		
    		for(int i=1;i<=n;i++) {
    			a[i][0] += a[i-1][0]; a[i][1] += a[i-1][1];
    			switch(s[i-1]) {
    			case 'W': a[i][1]++; break;
    			case 'S': a[i][1]--; break;
    			case 'A': a[i][0]--; break;
    			case 'D': a[i][0]++;
    			}
    		}
    		
    		for(int i=1;i<=n;i++) {
    			for(int j=0;j<2;j++) {
    				premin[i][j] = min(premin[i-1][j], a[i][j]);
    				premax[i][j] = max(premax[i-1][j], a[i][j]);
    			}
    		}
    		
    		for(int i=n;i>=0;i--) {
    			for(int j=0;j<2;j++	) {
    				sufmin[i][j] = min(sufmin[i+1][j], a[i][j]);
    				sufmax[i][j] = max(sufmax[i+1][j], a[i][j]);
    			}
    		}
    		
    		long[] len = new long[2];
    		len[0] = 1 + max(premax[n][0], 0) + max(-premin[n][0], 0);
    		len[1] = 1 + max(premax[n][1], 0) + max(-premin[n][1], 0);
    		long ans = len[0]*len[1];
    		
    		for(int i=1;i<=n+1;i++) {
    			for(int j=0;j<2;j++) {
    				long d1 = 1 + max(max(premax[i-1][j], 0), max(sufmax[i-1][j]+1, 0)) + max(max(-premin[i-1][j], 0), max(-sufmin[i-1][j]-1, 0));
    				long d2 = 1 + max(max(premax[i-1][j], 0), max(sufmax[i-1][j]-1, 0)) + max(max(-premin[i-1][j], 0), max(-sufmin[i-1][j]+1, 0));
    				ans = Math.min(ans, Math.min(d1, d2)*len[j^1]);
    			}
    		}
    		
    		out.println(ans);
    		
    		
    		
    	}
    	
    	out.close();
    }
	
	static int max(int a1, int a2) {
		return Math.max(a1, a2);
	}
	
	static int min(int a1,int a2) {
		return Math.min(a1, a2);
	}
	
    static final Random random=new Random();
    
    static <T> void shuffle(T[] arr) {
    	int n = arr.length;
    	for(int i=0;i<n;i++	) {
    		int k = random.nextInt(n);
    		T temp = arr[k]; arr[k] = arr[i]; arr[i] = temp;
    	}
    }
    
    	
    static void ruffleSort(int[] a) {
    	int n=a.length;//shuffle, then sort 
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); int temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }
    
    static void ruffleSort(long[] a) {
    	int n=a.length;//shuffle, then sort 
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); long temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }
   
  
    
    static void reverse(int[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++){
    		int temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }
    
    static void reverse(long[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++){
    		long temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }
    
    
    static <T> void reverse(T[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++) {
    		T temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }
    	
    	
    static class FastScanner{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");
     
    	public String next(){
    		while(!st.hasMoreElements()){
    			try{
    				st = new StringTokenizer(br.readLine());
    			} catch(IOException e){
    				e.printStackTrace();
    			}
    		}
    		return st.nextToken();
    	}
    		
    	public String nextLine() throws IOException {
    		return br.readLine();
    	}
    		
    	public int nextInt(){
    		return Integer.parseInt(next());
    	}
     
    	public int[] readArray(int n){
    		int[] a = new int[n];
    		for(int i=0;i<n;i++)
    			a[i] = nextInt();
    		return a;
    	}
    		
    	public long nextLong() {
    		return Long.parseLong(next());
    	}
    		
    	public char nextChar() {
    		return next().toCharArray()[0];
    	}
    }


   	
}
