


const { json } = require("express/lib/response");
const fs = require("fs");
const filePath = process.platform === "linux" ? "/dev/stdin" : "./예제.txt";
let input = fs.readFileSync(filePath).toString().trim().split('\n');
// const input = require('fs').readFileSync('/dev/stdin').toString().trim().split("\n")
const T = +input.shift();
const check = (theProblem) => {
let answer = 'NO';
let stack = [];
for (let i = 0; i < theProblem.length; i++) {
if (stack[stack.length - 1] === '(') {
if (theProblem[i] === ')') {
stack.pop();
}else{
stack.push(theProblem[i]);
}
}
else if (stack[stack.length - 1]===')'){
stack.push(theProblem[i]);
}
else{
stack.push(theProblem[i])
}
}
if (stack.length===0){
answer='YES';
}
return answer;
}
for (let i = 0; i < T; i++) {
let problem = input[i].trim().split('')
console.log(check(problem))
}