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

public class Main {
    void solve() {
        int t=ni();
        while(t-->0){
            char s[]=ns().toCharArray();
            int sz1=0,sz2=0;
            for(int i=0;i<s.length;i++){
                if(s[i]=='A' || s[i]=='D') sz1++;
                else sz2++;
            }
            int a1[]=new int[sz1+1];
            int a2[]=new int[sz2+1];
            int i1=1,i2=1;
            for(int i=0;i<s.length;i++){
                if(s[i]=='A') a1[i1++]=-1;
                else if(s[i]=='D') a1[i1++]=1;
                else if(s[i]=='W') a2[i2++]=1;
                else a2[i2++]=-1;
            }
            int ans1[]=find(a1),ans2[]=find(a2);
            long ans=Math.min(ans1[0]*1L*ans2[1],ans1[1]*1L*ans2[0]);
            pw.println(ans);
        }
    }
    int [] find(int a[]){
        if(a.length==1) {
            return new int[]{1,1};
        }
        int mx=0,mn=0;
        int c[]=new int[a.length];
        for(int i=1;i<a.length;i++){
            c[i]=c[i-1]+a[i];
            mx=Math.max(mx,c[i]);
            mn=Math.min(mn,c[i]);
        }

        int ans[]={mx-mn+1,Integer.MAX_VALUE};
        int sufMX[]=new int[a.length+1];
        int sufMN[]=new int[a.length+1];

        int prefMX[]=new int[a.length];
        int prefMN[]=new int[a.length];
        for(int i=a.length-1;i>=1;i--){
            sufMX[i]=sufMN[i]=c[i];
            if(i<a.length-1){
                sufMX[i]=Math.max(sufMX[i],sufMX[i+1]);
                sufMN[i]=Math.min(sufMN[i],sufMN[i+1]);
            }
        }
        for(int i=1;i<a.length;i++){
            prefMX[i]=prefMN[i]=c[i];

                prefMX[i]=Math.max(prefMX[i],prefMX[i-1]);
                prefMN[i]=Math.min(prefMN[i],prefMN[i-1]);

        }
        for(int i=1;i<a.length;i++){
            mx=Math.max(prefMX[i-1],Math.max(c[i-1]+1,sufMX[i]+1));
            mn=Math.min(prefMN[i-1],Math.min(c[i-1]+1,sufMN[i]+1));
            ans[1]=Math.min(ans[1],mx-mn+1);
           // pw.println(mx+" "+mn+" "+prefMX[i-1]+" "+sufMX[i-1]);
            mx=Math.max(prefMX[i-1],Math.max(c[i-1]-1,sufMX[i]-1));
            mn=Math.min(prefMN[i-1],Math.min(c[i-1]-1,sufMN[i]-1));
            ans[1]=Math.min(ans[1],mx-mn+1);
          //  pw.println(mx+" "+mn);
        }


     //   pw.println(ans[0]+" "+ans[1]);
        return ans;
    }
    long M = (long) 1e9 + 7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";

    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms");


    }

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
    }

}