#include<stdio.h>
#include<iostream>
#include<string.h>
#include<stack>
using namespace std;
int main(){
<span style="white-space:pre"> </span>int n=0;
<span style="white-space:pre"> </span>cin >> n;
<span style="white-space:pre"> </span>getchar();
<span style="white-space:pre"> </span>char str[256];
<span style="white-space:pre"> </span>while (n--){
<span style="white-space:pre"> </span>gets_s(str);
<span style="white-space:pre"> </span>int len = strlen(str);
<span style="white-space:pre"> </span>stack <char> s;
<span style="white-space:pre"> </span>char ch;
<span style="white-space:pre"> </span>bool ok = true;
<span style="white-space:pre"> </span>for (int i = 0; i < len;i++){
<span style="white-space:pre"> </span>ch = str[i];
<span style="white-space:pre"> </span>switch (ch)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>case'(':
<span style="white-space:pre"> </span>case'[':<span style="white-space:pre"> </span>s.push(ch); break;
<span style="white-space:pre"> </span>case')':
<span style="white-space:pre"> </span>case']':<span style="white-space:pre"> </span>if (s.empty()) ok = false;
<span style="white-space:pre"> </span>else {
<span style="white-space:pre"> </span>if (s.top() == '('&&ch != ')' || s.top() == '['&&ch != ']')
<span style="white-space:pre"> </span>ok = false;
<span style="white-space:pre"> </span>s.pop();
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>break;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>if (s.empty()&&ok)<span style="white-space:pre"> </span>cout << "Yes" << endl;
<span style="white-space:pre"> </span>else cout << "No" << endl;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>return 0;
}