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.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CYouAreGivenAWASDString solver = new CYouAreGivenAWASDString();
        solver.solve(1, in, out);
        out.close();
    }

    static class CYouAreGivenAWASDString {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int testcases = in.scanInt();
            while (testcases-- > 0) {
                char[] ar = in.scanString().toCharArray();
                int x = 0;
                int y = 0;
                int xMin = 0;
                int yMin = 0;
                int xMax = 0;
                int yMax = 0;
                ArrayList<Integer> xx = new ArrayList<>();
                ArrayList<Integer> yy = new ArrayList<>();
                xx.add(0);
                yy.add(0);
                for (char c : ar) {
                    if (c == 'D') y++;
                    else if (c == 'W') x--;
                    else if (c == 'S') x++;
                    else if (c == 'A') y--;
                    else throw new RuntimeException("NO");
                    xMin = Math.min(xMin, x);
                    yMin = Math.min(yMin, y);
                    xMax = Math.max(xMax, x);
                    yMax = Math.max(yMax, y);
                    if (xx.get(xx.size() - 1) != x) xx.add(x);
                    if (yy.get(yy.size() - 1) != y) yy.add(y);
                }
                long ans = (xMax - xMin + 1l) * (yMax - yMin + 1);
                boolean removeX = true;
                boolean removeY = true;
                {
                    {
                        int lowXmin = xx.size();
                        int highXmin = -1;
                        for (int i = 0; i < xx.size(); i++) {
                            if (xx.get(i) == xMin) {
                                lowXmin = Math.min(lowXmin, i);
                                highXmin = Math.max(highXmin, i);
                            }
                        }
                        for (int i = lowXmin; i <= highXmin; i++) if (xx.get(i) == xMax) removeX = false;
                    }
                    {
                        int lowXmax = xx.size();
                        int highXmax = -1;
                        for (int i = 0; i < xx.size(); i++) {
                            if (xx.get(i) == xMax) {
                                lowXmax = Math.min(lowXmax, i);
                                highXmax = Math.max(highXmax, i);
                            }
                        }
                        for (int i = lowXmax; i <= highXmax; i++) if (xx.get(i) == xMin) removeX = false;

                    }

                }
                {
                    {
                        int lowYmin = yy.size();
                        int highYmin = -1;
                        for (int i = 0; i < yy.size(); i++) {
                            if (yy.get(i) == yMin) {
                                lowYmin = Math.min(lowYmin, i);
                                highYmin = Math.max(highYmin, i);
                            }
                        }
                        for (int i = lowYmin; i <= highYmin; i++) if (yy.get(i) == yMax) removeY = false;
                    }
                    {
                        int lowYmax = yy.size();
                        int highYmax = -1;
                        for (int i = 0; i < yy.size(); i++) {
                            if (yy.get(i) == yMax) {
                                lowYmax = Math.min(lowYmax, i);
                                highYmax = Math.max(highYmax, i);
                            }
                        }
                        for (int i = lowYmax; i <= highYmax; i++) if (yy.get(i) == yMin) removeY = false;

                    }

                }
                if (xMax - xMin == 0) {
                    if (removeY) ans = Math.min(ans, (Math.max(2, yMax - yMin) * (xMax - xMin + 1l)));
                } else if (yMax - yMin == 0) {
                    if (removeX) ans = Math.min(ans, Math.max(2, xMax - xMin) * (yMax - yMin + 1l));
                } else {
                    if (removeX) ans = Math.min(ans, Math.max(2, xMax - xMin) * (yMax - yMin + 1l));
                    if (removeY) ans = Math.min(ans, Math.max(2, yMax - yMin) * (xMax - xMin + 1l));
                }
                out.println(ans);
            }
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        public String scanString() {
            int c = scan();
            if (c == -1) return null;
            while (isWhiteSpace(c)) c = scan();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = scan();
            } while (!isWhiteSpace(c));
            return res.toString();
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}

