uses crt;
var f,f1:text; i,n,d,g:longint; s,t:string;
begin
clrscr;
assign(f,'input.pas');reset(f);
assign(f1,'output.pas');rewrite(f1);
readln(f,n);
for g:=1 to n do
begin
readln(f,t); s:='';
for i:=1 to length(t) do
if (t[i]='(')or(t[i]=')') then s:=s+t[i];
repeat
d:=0;
for i:=1 to length(s)-1 do
if (s[i]='(')and(s[i+1]=')') then begin inc(d); delete(s,i,2); end;
until d=0;
if s='' then writeln(f1,'YES') else writeln(f1,'NO');
end;
close(f1);
close(f);
end.