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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Andy Phan
 */
public class c {
    public static void main(String[] args) {
        FS in = new FS(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        int T = in.nextInt();
        
        int[] map = new int['Z'];
        map['W'] = 0;
        map['S'] = 1;
        map['A'] = 2;
        map['D'] = 3;
        while(T-->0) {
            String s = in.next();
            int n = s.length();
            long[][] bounds = new long[4][n+1]; //0 = W, 1 = S, 2 = A, 3 = D
            for(int i = 0; i < n; i++) {
                int type = map[s.charAt(i)];
                bounds[type][i+1] = Math.max(0, bounds[type][i]-1);
                bounds[type^1][i+1] = bounds[type^1][i]+1;
                bounds[type^2][i+1] = bounds[type^2][i];
                bounds[type^3][i+1] = bounds[type^3][i];
            }
            
            long[][] bounds2 = new long[4][n+1]; //0 = W, 1 = S, 2 = A, 3 = D
            for(int i = n-1; i >= 0; i--) {
                int type = map[s.charAt(i)]^1;
                bounds2[type][i] = Math.max(0, bounds2[type][i+1]-1);
                bounds2[type^1][i] = bounds2[type^1][i+1]+1;
                bounds2[type^2][i] = bounds2[type^2][i+1];
                bounds2[type^3][i] = bounds2[type^3][i+1];
            }
            
            long min = (bounds2[0][0]+bounds2[1][0]+1)*(bounds2[2][0]+bounds2[3][0]+1);
            for(int i = 0; i < n; i++) {
                for(int j = 0; j < 4; j++) {
                    long[] bound = new long[4];
                    for(int k = 0; k < 4; k++) bound[k] = bounds[k][i];
                    bound[j] = Math.max(bound[j], Math.max(0, bounds2[j][i]-1));
                    bound[j^1] = Math.max(bound[j^1], bounds2[j^1][i]+1);
                    bound[j^2] =Math.max(bound[j^2], bounds2[j^2][i]);
                    bound[j^3] = Math.max(bound[j^3], bounds2[j^3][i]);
                    long size = (bound[0]+bound[1]+1)*(bound[2]+bound[3]+1);
                    min = Math.min(min, size);
                }
            }
            System.out.println(min);
        }
        
        out.close();
    }
    
    static class FS {

        BufferedReader in;
        StringTokenizer token;
        
        public FS(InputStream str) {
            in = new BufferedReader(new InputStreamReader(str));
        }
        
        public String next() {
            if (token == null || !token.hasMoreElements()) {
                try {
                    token = new StringTokenizer(in.readLine());
                } catch (IOException ex) {
                }
                return next();
            }
            return token.nextToken();
        }
        
        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}
