Problem: You are given a string s, consisting of brackets of two types: '(', ')', '[' and ']'.

A string is called a regular bracket sequence (RBS) if it's of one of the following types: 

  * empty string; 
  * '(' + RBS + ')'; 
  * '[' + RBS + ']'; 
  * RBS + RBS. 



where plus is a concatenation of two strings.

In one move you can choose a non-empty subsequence of the string s (not necessarily consecutive) that is an RBS, remove it from the string and concatenate the remaining parts without changing the order.

What is the maximum number of moves you can perform?

Input

The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.

Each of the next t lines contains a non-empty string, consisting only of characters '(', ')', '[' and ']'. The total length of the strings over all testcases doesn't exceed 2 ⋅ 10^5.

Output

For each testcase print a single integer — the maximum number of moves you can perform on a given string s.

Example

Input


5
()
[]()
([)]
)]([
)[(]


Output


1
2
2
0
1

Note

In the first example you can just erase the whole string.

In the second example you can first erase the brackets on positions 1 and 2: "[]()", then "()" is left. After that you can erase it whole. You could erase the whole string from the beginning but you would get one move instead of two.

In the third example you can first erase the brackets on positions 1 and 3: "([)]". They form an RBS "()". Then "[]" is left, so you can erase it whole.

In the fourth example there is no subsequence that is an RBS, so you can't perform a move at all.

In the fifth example you can erase the brackets on positions 2 and 4: ")[(]" and get ")(" as a result. You can erase nothing from it.

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;
import static java.util.Collections.*;
import static java.lang.Math.*;
import java.util.stream.*;
import static java.util.Arrays.*;
import java.lang.reflect.Array;

@SuppressWarnings("unchecked")
public class C_Two_Brackets {
    public static PrintWriter out;
    public static InputReader in;
    public static long MOD = 1_000_000_007;
    
    public static void main(String[] args)throws IOException {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        
        int cases = in.nextInt();
        
        tloop:
        for(int t = 0; t < cases; t++){
            char[] arr = in.next().toCharArray();
            int n = arr.length;
            int p2 = 0; int ans = 0;
            for(int i=0;i<n;i++){
                if(arr[i]!='(') continue;
                p2 = max(p2,i);
                while(p2<n && arr[p2]!=')') p2++;
                if(p2==n) break;
                ans++; p2++;
            }
            p2 = 0;
            for(int i=0;i<n;i++){
                if(arr[i]!='[') continue;
                p2 = max(p2,i);
                while(p2<n && arr[p2]!=']') p2++;
                if(p2==n) break;
                ans++; p2++;
            }
            out.println(ans);
        }
        
        out.close();
    }
    static void debug(Object... objs){
        for(Object obj : objs){
            out.print(obj+", ");
        }
        out.println();
    }
    static void fill(Object obj, Object v){
        int ln = Array.getLength(obj);
        for(int i=0; i<ln; i++){
            Object elem = Array.get(obj, i);
            if(elem!=null && elem.getClass().isArray()) fill(elem, v);
            else Array.set(obj, i, v);
        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int[] nextArrI(int n) {
            int[] a=new int[n];
            for(int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        
        public long[] nextArrL(int n) {
            long[] a=new long[n];
            for (int i=0; i<n; i++) a[i]=nextLong();
            return a;
        }
    }

}