#include <bits/stdc++.h> using namespace std; const int N = 2000005; int a[N]; pair<int, int> dp[N]; inline void solve(){ string s; cin >> s; int n = (int)s.size(); for(int i = 0; i < n; i++){ a[i] = -1; } for(int i = 1; i < n; i++){ if(s[i] == ')'){ int j = i - 1; bool flg = false; while(j >= 0){ if(s[j] == '('){ flg = true; break; }else if(a[j] == -1){ break; }else{ j = a[j] - 1; } } if(flg){ a[i] = j; if(j > 0 && a[j - 1] != -1){ a[i] = a[j - 1]; } } } } dp[0] = {0, 0}; for(int i = 1; i <= n; i++){ int lo = a[i - 1]; dp[i] = dp[i - 1]; if(lo == -1){ // Do nothing }else if(dp[i].first < dp[lo].first + i - lo){ dp[i] = {dp[lo].first + i - lo, dp[lo].second + 1}; }else if(dp[i].first == dp[lo].first + i - lo){ dp[i].second = min(dp[i].second, dp[lo].second + 1); } } cout << n - dp[n].first << " " << dp[n].second << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while(t--)solve(); return 0; }