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.*;
import java.util.*;

public class C implements Runnable {
	public static void main (String[] args) {new Thread(null, new C(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		int t = fs.nextInt();
		
		while(t-->0) {
			char[] str = fs.next().toCharArray();
			int n = str.length;
			StringBuilder LR = new StringBuilder();
			StringBuilder UD = new StringBuilder();
			for(int i = 0; i < n; i++) {
				if(str[i] == 'A' || str[i] == 'D') {
					LR.append(str[i]);
				}
				else {
					UD.append(str[i]);
				}
			}
			
			int min1 = 0, max1 = 0;
			int min2 = 0, max2 = 0;
			int cur = 0;
			for(int i = 0; i < LR.length(); i++) {
				char now = LR.charAt(i);
				if(now == 'A') {
					cur--;
				}
				else {
					cur++;
				}
				min1 = Math.min(min1, cur);
				max1 = Math.max(max1, cur);
			}
			
			cur = 0;
			for(int i = 0; i < UD.length(); i++) {
				char now = UD.charAt(i);
				if(now == 'W') {
					cur++;
				}
				else {
					cur--;
				}
				min2 = Math.min(min2, cur);
				max2 = Math.max(max2, cur);
			}

			long res = (long)(max1-min1+1)*(max2-min2+1);
			long ret = work(min1, max1, UD.toString());
			ret = Math.min(ret, work(min2, max2, LR.toString()));
			out.println(Math.min(res, ret));
		}
		
		out.close();
	}
	
	long work(int x1, int x2, String str) {
		int n = str.length();
		int[] pref = new int[n];
		for(int i = 0; i < n; i++) {
			char now = str.charAt(i);
			if(now == 'A' || now == 'S') {
				pref[i]--;
			}
			else {
				pref[i]++;
			}
			if(i > 0) pref[i] += pref[i-1];
		}
		int[] maxP = new int[n], minP = new int[n];
		int[] maxS = new int[n], minS = new int[n];
		for(int i = 0; i < n; i++) {
			maxP[i] = pref[i];
			minP[i] = pref[i];
			if(i > 0) {
				maxP[i] = Math.max(maxP[i], maxP[i-1]);
				minP[i] = Math.min(minP[i], minP[i-1]);
			}
		}
		for(int i = n-1; i >= 0; i--) {
			maxS[i] = pref[i];
			minS[i] = pref[i];
			if(i < n-1) {
				maxS[i] = Math.max(maxS[i], maxS[i+1]);
				minS[i] = Math.min(minS[i], minS[i+1]);
			}
		}
		
		long res = Long.MAX_VALUE;
		int[] delta = {1, -1};
		
		int curMin = 0, curMax = 0, cur = 0;
		for(int i = 0; i < n; i++) {
			for(int k : delta) {
				cur += k;
				int min1 = minS[i]-(i > 0 ? pref[i-1] : 0);
				int max1 = maxS[i]-(i > 0 ? pref[i-1] : 0);
				int nmin = cur, nmax = cur;
				min1 += cur;
				max1 += cur;
				nmin = Math.min(nmin, Math.min(curMin, min1));
				nmax = Math.max(nmax, Math.max(curMax, max1));
				res = Math.min(res, (long)(nmax-nmin+1)*(x2-x1+1));
				
				cur -= k;
			}
			
			if(i < n) {
				cur += pref[i];
				if(i > 0) cur -= pref[i-1];
				curMin = Math.min(curMin, cur);
				curMax = Math.max(curMax, cur);
			}
		}
		
		return res;
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}