///P4-成雙成對

#include <iostream>
#include <cstring>
#include <string>
#include <stack>
#include <cstdlib>
#define MAX 150
using namespace std;
char s[MAX];

int main()
{
    int n;
    cin.getline(s,MAX);
    n = atoi(s);
    while (n--)
    {
        cin.getline(s,MAX);
        bool valid = true;
        stack<char> cs;

        for (int i=0; i<strlen(s); i++)
        {
            switch(s[i])
            {
            case '(':
            case '[':
                cs.push(s[i]);
                break;
            case ')':
                if (!cs.empty() && cs.top()=='(')
                    cs.pop();
                else
                {
                    valid = false;
                    break;
                }
                break;

            case ']':
                if (!cs.empty() && cs.top()=='[')
                    cs.pop();
                else
                {
                    valid = false;
                    break;
                }
                break;

            default:
                break;
            }
        }

        if (cs.empty() && valid) cout << "Valid" << endl;
        else cout << "Try again" << endl;
    }

    return 0;
}


/*
範例輸入
3
[(3 + 6 ) * 4 - 2] =
[[([4*(3+5)])*2)+5)] =
([(3+5)*[4+6]/(5*8)]*2)-( 5 ^ 2) =


範例輸出
Valid
Try again
Valid

--
8
([])
(([()])))
([()[]()])()
)(
(]
((((((
]]]
][]

Valid
Try again
Valid
Try again
Try again
Try again
Try again
Try again

*/
