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.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author beginner1010
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        int length;

        boolean can(char[] s, char a, char b) {
            int pos = 0;
            int n = s.length;
            int max = 0;
            int min = 0;
            int maxBoundry = 0;
            int minBoundry = 0;

            int[] minFromLeft = new int[n + 1];
            int[] maxFromLeft = new int[n + 1];

            for (int i = 0; i < s.length; i++) {
                if (s[i] == a) pos++;
                else if (s[i] == b) pos--;
                max = Math.max(max, pos);
                min = Math.min(min, pos);
                minFromLeft[i] = min;
                maxFromLeft[i] = max;
            }
            maxBoundry = max;
            minBoundry = min;
            length = max - min;
            int[] maxFromRight = new int[n + 1];
            int[] minFromRight = new int[n + 1];
            maxFromRight[n] = pos;
            minFromRight[n] = pos;
            max = pos;
            min = pos;
            for (int i = n - 1; i >= 0; i--) {
                if (s[i] == b) pos++;
                else if (s[i] == a) pos--;
                max = Math.max(max, pos);
                min = Math.min(min, pos);
                maxFromRight[i] = Math.max(max, pos);
                minFromRight[i] = Math.min(min, pos);
            }
            for (int i = 0; i < n; i++) {
                if (minFromRight[i + 1] > minBoundry && maxFromLeft[i] < maxBoundry) {
                    return true;
                }
                if (maxFromRight[i + 1] < maxBoundry && minFromLeft[i] > minBoundry) {
                    return true;
                }
            }
            return false;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int T = in.nextInt();
            for (int t = 0; t < T; t++) {
                char[] s = in.nextLine().toCharArray();
                boolean ans1 = can(s, 'A', 'D');
                long lenA = length + 1;
                boolean ans2 = can(s, 'W', 'S');
                long lenB = length + 1;
                long area = lenA * lenB;
                if (ans1 == true) {
                    area = Math.min(area, (lenA - 1) * lenB);
                }
                if (ans2 == true) {
                    area = Math.min(area, lenA * (lenB - 1));
                }
                out.println(area);
            }
        }

    }

    static class InputReader {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputStream stream;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        private int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isWhitespace(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isWhitespace(c));
            return res * sgn;
        }

        public String nextLine() {
            int c = read();
            while (isWhitespace(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

    }
}

