沟槽的思维题。

显然,奇数长度的序列不管怎样进行更改都不可能变为合法。

而对于偶数长度的序列而言,必然合法。其中,长度为2的序列只用一种合法序列“()”,而长度不为2的一定有若干种不同的合法序列,如“((((”可以是“()()”也可以是“(())”,其他长度同理。

#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define fi first
#define se second
#define endl '\n'
// ---
using ll=long long;
using ull=unsigned long long;
// ---
template<class K,class V>
using umap=unordered_map<K,V>;
template<class T>
using max_heap=priority_queue<T>;
template<class T>
using min_heap=priority_queue<T,vector<T>,greater<T>>;
// ---
// 创建随机引擎
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// 生成一个在 [l, r] 间的随机整数
int randint(int l, int r) {
    uniform_int_distribution<int> dist(l, r);
    return dist(rng);
}

// 生成一个 [0,1) 的随机实数
double randdbl() {
    uniform_real_distribution<double> dist(0.0, 1.0);
    return dist(rng);
}
// ---
const int INF=1e9;
const ll  LINF=4e18; 
const int mod=1e9+7;
const double eps=1e-9; 
// ---
string str;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t; cin>>t;
	while(t--)
	{
		cin>>str;
		int n=str.size();
		if(n&1)			cout<<-1<<endl;
		else if(n==2)	cout<<"()"<<endl;
		else			cout<<"There are multiple solutions"<<endl;
	}
	return 0;
}