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.OutputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.BufferedWriter;
import java.util.Random;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

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

    static class CVamZadanaWASDStroka {
        int[] code;
        int[] dx;
        int[] dy;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            if (code == null) init();
            if (false) {
                new Tester().test();
                return;
            }
            int t = in.readInt();
            while (t-- > 0) {
                char[] s = in.next().toCharArray();
                long answer = new Solver(s).solve();
                out.printLine(answer);
            }
        }

        void init() {
            code = new int[1 << 8];
            code['W'] = 0;
            code['A'] = 1;
            code['S'] = 2;
            code['D'] = 3;
            dx = new int[]{-1, 0, 1, 0};
            dy = new int[]{0, -1, 0, 1};
        }

        class Tester {
            Random rnd = new Random(239);

            void test() {
                for (int t = 0; ; t++) {
                    int n = rnd.nextInt(5) + 1;
                    char[] s = new char[n];
                    for (int i = 0; i < n; i++) s[i] = "WASD".charAt(rnd.nextInt(4));
                    long solve = new Solver(s).solve();
                    long naive = new Naive(s).solve();
                    if (solve != naive) {
                        System.out.println(t + " s naive solve");
                        System.out.println(new String(s));
                        System.out.println(naive);
                        System.out.println(solve);
                        return;
                    }
                }
            }

        }

        class Naive {
            String s;

            public Naive(char[] s) {
                this.s = new String(s);
            }

            long solve() {
                long ans = getAns(s);
                for (int i = 0; i <= s.length(); i++) {
                    for (char c : "WASD".toCharArray()) {
                        String t = s.substring(0, i) + c + s.substring(i);
                        ans = Math.min(ans, getAns(t));
                    }
                }
                return ans;
            }

            long getAns(String s) {
                CVamZadanaWASDStroka.Field field = new CVamZadanaWASDStroka.Field();
                for (char c : s.toCharArray()) {
                    int d = code[c];
                    field = field.move(dx[d], dy[d]);
                }
                return field.area();
            }

        }

        class Solver {
            char[] s;
            int[] moves;

            Solver(char[] s) {
                this.s = s;
                int n = s.length;
                moves = new int[n];
                for (int i = 0; i < n; i++) moves[i] = code[s[i]];
            }

            long solve() {
                int n = s.length;

                CVamZadanaWASDStroka.Field[] revFields = new CVamZadanaWASDStroka.Field[n + 1];
                revFields[n] = new CVamZadanaWASDStroka.Field();
                for (int i = n - 1; i >= 0; i--) {
                    revFields[i] = revFields[i + 1].move(-dx[moves[i]], -dy[moves[i]]);
                }

                CVamZadanaWASDStroka.Field[] fields = new CVamZadanaWASDStroka.Field[n + 1];
                fields[0] = new CVamZadanaWASDStroka.Field();
                for (int i = 0; i < n; i++) {
                    fields[i + 1] = fields[i].move(dx[moves[i]], dy[moves[i]]);
                }

                long answer = fields[n].area();
                for (int i = 0; i <= n; i++) {
                    CVamZadanaWASDStroka.Field f1 = fields[i];
                    CVamZadanaWASDStroka.Field f2 = revFields[i];
                    for (int d = 0; d < 4; d++) {
                        CVamZadanaWASDStroka.Field f3 = f1.move(dx[d], dy[d]);
                        CVamZadanaWASDStroka.Field f4 = f3.combine(f2);
                        long area = f4.area();
                        answer = Math.min(answer, area);
                    }
                }
                return answer;
            }

        }

        static class Field {
            int minX;
            int maxX;
            int minY;
            int maxY;
            int lastX;
            int lastY;

            public Field(int minX, int maxX, int minY, int maxY, int lastX, int lastY) {
                this.minX = minX;
                this.maxX = maxX;
                this.minY = minY;
                this.maxY = maxY;
                this.lastX = lastX;
                this.lastY = lastY;
            }

            public Field() {
            }

            public Field(int minX, int maxX, int minY, int maxY) {
                this.minX = minX;
                this.maxX = maxX;
                this.minY = minY;
                this.maxY = maxY;
            }

            CVamZadanaWASDStroka.Field apply(int x, int y) {
                return new CVamZadanaWASDStroka.Field(Math.min(minX, x), Math.max(maxX, x), Math.min(minY, y), Math.max(maxY, y), x, y);
            }

            long area() {
                return (maxX - minX + 1L) * (maxY - minY + 1L);
            }

            CVamZadanaWASDStroka.Field move(int dx, int dy) {
                return apply(lastX + dx, lastY + dy);
            }

            CVamZadanaWASDStroka.Field combine(CVamZadanaWASDStroka.Field other) {
                return new CVamZadanaWASDStroka.Field(
                        Math.min(minX, lastX - (other.lastX - other.minX)),
                        Math.max(maxX, lastX + (other.maxX - other.lastX)),
                        Math.min(minY, lastY - (other.lastY - other.minY)),
                        Math.max(maxY, lastY + (other.maxY - other.lastY))
                );
            }

            public String toString() {
                return "Field{" +
                        "minX=" + minX +
                        ", maxX=" + maxX +
                        ", minY=" + minY +
                        ", maxY=" + maxY +
                        ", lastX=" + lastX +
                        ", lastY=" + lastY +
                        '}';
            }

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(long i) {
            writer.println(i);
        }

    }

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

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

        public 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 readInt() {
            int c = read();
            while (isSpaceChar(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 (!isSpaceChar(c));
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

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

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

