HDU 多校 6400 Parentheses Matrix(构造)
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N= 1e3 + 5 , M= 2e4 + 5 , inf= 0x3f3f3f3f , mod= 1e9 + 7 ;
const int hashmod[ 4 ] = { 402653189 , 805306457 , 1610612741 , 998244353 } ;
# define mst ( a, b) memset ( a, b, sizeof a)
# define PII pair< int , int >
# define PLL pair< ll, ll>
# define x first
# define y second
# define pb emplace_back
# define SZ ( a) ( int ) a. size ( )
# define rep ( i, a, b) for ( int i= a; i<= b; ++ i)
# define per ( i, a, b) for ( int i= a; i>= b; -- i)
# define IOS ios:: sync_with_stdio ( false ) , cin. tie ( nullptr )
void Print ( int * a, int n) { for ( int i= 1 ; i< n; i++ ) printf ( "%d " , a[ i] ) ; printf ( "%d\n" , a[ n] ) ;
}
template < typename T >
void cmx ( T & x, T y) { if ( x< y) x= y;
}
template < typename T >
void cmn ( T & x, T y) { if ( x> y) x= y;
}
char a[ N] [ N] ;
int main ( ) { int t; cin>> t; while ( t-- ) { int n, m; cin>> n>> m; if ( ( n% 2 == 1 ) && ( m% 2 == 1 ) ) { rep ( i, 1 , n) { rep ( j, 1 , m) putchar ( '(' ) ; putchar ( '\n' ) ; } continue ; } else if ( ( m% 2 == 1 ) ) { rep ( i, 1 , n) { if ( i& 1 ) rep ( j, 1 , m) putchar ( '(' ) ; else rep ( j, 1 , m) putchar ( ')' ) ; putchar ( '\n' ) ; } } else if ( ( n% 2 == 1 ) ) { rep ( i, 1 , n) { rep ( j, 1 , m) putchar ( j& 1 ? '(' : ')' ) ; putchar ( '\n' ) ; } } else { bool rev = 0 ; if ( n > m) swap ( n, m) , rev = true ; if ( n == 2 ) { rep ( i, 1 , m) a[ 1 ] [ i] = '(' , a[ 2 ] [ i] = ')' ; } else if ( n== 4 ) { rep ( i, 1 , n) { rep ( j, 1 , m/ 2 ) a[ i] [ j] = i& 1 ? '(' : ')' ; rep ( j, m/ 2 + 1 , m) a[ i] [ j] = i<= n/ 2 ? '(' : ')' ; } } else { rep ( i, 1 , n) { rep ( j, 1 , m) { if ( i== 1 || j== 1 ) a[ i] [ j] = '(' ; else if ( i== n|| j== m) a[ i] [ j] = ')' ; else if ( ( i+ j) & 1 ) a[ i] [ j] = '(' ; else a[ i] [ j] = ')' ; } } } if ( rev) { rep ( i, 1 , m) { rep ( j, 1 , n) putchar ( a[ j] [ i] ) ; putchar ( '\n' ) ; } } else { rep ( i, 1 , n) { rep ( j, 1 , m) putchar ( a[ i] [ j] ) ; putchar ( '\n' ) ; } } } } return 0 ;
}