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).
/**
 * BaZ :D
 */

import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main
{
    static MyScanner scan;
    static PrintWriter pw;
    static long MOD = 1_000_000_007;
    static long INF = 1_000_000_000_000_000_000L;
    static long inf = 2_000_000_000;
    public static void main(String[] args) {
        new Thread(null,null,"BaZ",1<<25)
        {
            public void run()
            {
                try
                {
                    solve();
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }
    static void solve() throws IOException
    {
        //initIo(true);
        initIo(false);
        StringBuilder sb = new StringBuilder();
        int t = ni();
        while(t-->0) {
            char c[] = ne().toCharArray();
            int n = c.length;
            int pref_ver[] = new int[n+1];
            int pref_hor[] = new int[n+1];
            for(int i=1;i<=n;++i) {
                if(c[i-1]=='W') {
                    pref_ver[i] = 1;
                }
                else if(c[i-1]=='S') {
                    pref_ver[i] = -1;
                }
                else if(c[i-1]=='A') {
                    pref_hor[i] = -1;
                }
                else {
                    pref_hor[i] = 1;
                }
                pref_hor[i]+=pref_hor[i-1];
                pref_ver[i]+=pref_ver[i-1];
            }
//            pa("pref_hor", pref_hor);
//            pa("pref_ver", pref_ver);
            int max_suff_ver[] = new int[n+1];
            int max_suff_hor[] = new int[n+1];
            int min_suff_ver[] = new int[n+1];
            int min_suff_hor[] = new int[n+1];
            int max_pref_ver[] = new int[n+1];
            int max_pref_hor[] = new int[n+1];
            int min_pref_ver[] = new int[n+1];
            int min_pref_hor[] = new int[n+1];
            for(int i=n;i>=0;--i) {
                min_suff_hor[i] = max_suff_hor[i] = pref_hor[i];
                min_suff_ver[i] = max_suff_ver[i] = pref_ver[i];
                min_pref_hor[i] = max_pref_hor[i] = pref_hor[i];
                min_pref_ver[i] = max_pref_ver[i] = pref_ver[i];
                if(i<n) {
                    min_suff_hor[i] = min(min_suff_hor[i+1], min_suff_hor[i]);
                    max_suff_hor[i] = max(max_suff_hor[i+1], max_suff_hor[i]);
                    min_suff_ver[i] = min(min_suff_ver[i+1], min_suff_ver[i]);
                    max_suff_ver[i] = max(max_suff_ver[i+1], max_suff_ver[i]);
                }
            }
            for(int i=1;i<=n;++i) {
                min_pref_hor[i] = min(min_pref_hor[i-1], min_pref_hor[i]);
                max_pref_hor[i] = max(max_pref_hor[i-1], max_pref_hor[i]);
                min_pref_ver[i] = min(min_pref_ver[i-1], min_pref_ver[i]);
                max_pref_ver[i] = max(max_pref_ver[i-1], max_pref_ver[i]);
            }
//            pa("min_pref_hor", min_pref_hor);
//            pa("max_pref_hor", max_pref_hor);
//            pa("min_suff_hor", min_suff_hor);
//            pa("max_suff_hor", max_suff_hor);
//            pa("min_pref_ver", min_pref_ver);
//            pa("max_pref_ver", max_pref_ver);
//            pa("min_suff_ver", min_suff_ver);
//            pa("max_suff_ver", max_suff_ver);
            long now = 1L * (max_suff_hor[0] - min_suff_hor[0] + 1) * (max_suff_ver[0] - min_suff_ver[0] + 1);
            //pl("Orginially: " + now);
            int new_ver_min, new_hor_min, new_ver_max, new_hor_max;
            for(int i=1;i<=n;++i) {
                // increase ver by 1
                new_ver_min = (i==0 ? Integer.MAX_VALUE : min_pref_ver[i-1]);
                new_ver_min = min(new_ver_min, min_suff_ver[i]+1);
                new_ver_min = min(new_ver_min, pref_ver[i-1]+1);
                new_ver_max = (i==0 ? Integer.MIN_VALUE : max_pref_ver[i-1]);
                new_ver_max = max(new_ver_max, max_suff_ver[i]+1);
                new_ver_max = max(new_ver_max, pref_ver[i-1] + 1);
                new_hor_min = min_pref_hor[n];
                new_hor_max = max_pref_hor[n];
                now = min(now,  1L * (new_hor_max - new_hor_min + 1) * (new_ver_max - new_ver_min + 1));

                //decrease ver by 1
                new_ver_min = (i==0 ? Integer.MAX_VALUE : min_pref_ver[i-1]);
                new_ver_min = min(new_ver_min, min_suff_ver[i]-1);
                new_ver_min = min(new_ver_min, pref_ver[i-1]-1);
                new_ver_max = (i==0 ? Integer.MIN_VALUE : max_pref_ver[i-1]);
                new_ver_max = max(new_ver_max, max_suff_ver[i]-1);
                new_ver_max = max(new_ver_max, pref_ver[i-1]-1);
                new_hor_min = min_pref_hor[n];
                new_hor_max = max_pref_hor[n];
                now = min(now,  1L * (new_hor_max - new_hor_min + 1) * (new_ver_max - new_ver_min + 1));

                //increase hor by 1
                new_hor_min = (i==0 ? Integer.MAX_VALUE : min_pref_hor[i-1]);
                new_hor_min = min(new_hor_min, min_suff_hor[i]+1);
                new_hor_min = min(new_hor_min, pref_hor[i-1]+1);
                new_hor_max = (i==0 ? Integer.MIN_VALUE : max_pref_hor[i-1]);
                new_hor_max = max(new_hor_max, max_suff_hor[i]+1);
                new_hor_max = max(new_hor_max, pref_hor[i-1]+1);
                new_ver_min = min_pref_ver[n];
                new_ver_max = max_pref_ver[n];
                now = min(now,  1L * (new_hor_max - new_hor_min + 1) * (new_ver_max - new_ver_min + 1));

                //decrease hor by 1
                new_hor_min = (i==0 ? Integer.MAX_VALUE : min_pref_hor[i-1]);
                new_hor_min = min(new_hor_min, min_suff_hor[i]-1);
                new_hor_min = min(new_hor_min, pref_hor[i-1]-1);
                new_hor_max = (i==0 ? Integer.MIN_VALUE : max_pref_hor[i-1]);
                new_hor_max = max(new_hor_max, max_suff_hor[i]-1);
                new_hor_max = max(new_hor_max, pref_hor[i-1]-1);
                new_ver_min = min_pref_ver[n];
                new_ver_max = max_pref_ver[n];
                now = min(now,  1L * (new_hor_max - new_hor_min + 1) * (new_ver_max - new_ver_min + 1));
            }
            pl(now);
        }
        pw.flush();
        pw.close();
    }
    static void initIo(boolean isFileIO) throws IOException {
        scan = new MyScanner(isFileIO);
        if(isFileIO) {
            pw = new PrintWriter("/Users/amandeep/Desktop/output.txt");
        }
        else {
            pw = new PrintWriter(System.out, true);
        }
    }
    static int ni() throws IOException
    {
        return scan.nextInt();
    }
    static long nl() throws IOException
    {
        return scan.nextLong();
    }
    static double nd() throws IOException
    {
        return scan.nextDouble();
    }
    static String ne() throws IOException
    {
        return scan.next();
    }
    static String nel() throws IOException
    {
        return scan.nextLine();
    }
    static void pl()
    {
        pw.println();
    }
    static void p(Object o)
    {
        pw.print(o+" ");
    }
    static void pl(Object o)
    {
        pw.println(o);
    }
    static void psb(StringBuilder sb)
    {
        pw.print(sb);
    }
    static void pa(String arrayName, Object arr[])
    {
        pl(arrayName+" : ");
        for(Object o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, int arr[])
    {
        pl(arrayName+" : ");
        for(int o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, long arr[])
    {
        pl(arrayName+" : ");
        for(long o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, double arr[])
    {
        pl(arrayName+" : ");
        for(double o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, char arr[])
    {
        pl(arrayName+" : ");
        for(char o : arr)
            p(o);
        pl();
    }
    static void pa(String listName, List list)
    {
        pl(listName+" : ");
        for(Object o : list)
            p(o);
        pl();
    }
    static void pa(String arrayName, Object[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(Object o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, int[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(int o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, long[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(long o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, char[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(char o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, double[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(double o : arr[i])
                p(o);
            pl();
        }
    }
    static class MyScanner
    {
        BufferedReader br;
        StringTokenizer st;
        MyScanner(boolean readingFromFile) throws IOException
        {
            if(readingFromFile) {
                br = new BufferedReader(new FileReader("/Users/amandeep/Desktop/input.txt"));
            }
            else {
                br = new BufferedReader(new InputStreamReader(System.in));
            }
        }
        String nextLine()throws IOException
        {
            return br.readLine();
        }
        String next() throws IOException
        {
            if(st==null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
        int nextInt() throws IOException
        {
            return Integer.parseInt(next());
        }
        long nextLong() throws IOException
        {
            return Long.parseLong(next());
        }
        double nextDouble() throws IOException
        {
            return Double.parseDouble(next());
        }
    }
}