#include #define forn(i,s,t) for(register int i=(s); i<=(t); ++i) #define form(i,s,t) for(register int i=(s); i>=(t); --i) #define rep(i,s,t) for(register int i=(s); i<(t); ++i) using namespace std; const int N = 2e5 + 4; vector T[N]; int sl; int n, q; char s[N]; int dep[N], stk[N], top, l[N], r[N], tai[N], up[20][N]; void dfs(int u) { forn (i, 1, 19) up[i][u] = up[i - 1][up[i - 1][u]]; for (int v : T[u]) up[0][v] = u, dep[v] = dep[u] + 1, dfs(v); } inline int lca(int u, int v) { if (dep[u] < dep[v]) swap(u, v); int lft = dep[u] - dep[v]; for (int i = 0; lft; lft >>= 1, ++i) if (lft & 1) u = up[i][u]; if (u == v) return u; form (i, 19, 0) if (up[i][u] != up[i][v]) u = up[i][u], v = up[i][v]; return up[0][u]; } int main() { scanf("%d%d", &n, &q); scanf("%s", s + 1); forn (i, 1, n) { if (s[i] == '(') stk[++top] = i, tai[i] = ++sl; else { T[tai[stk[top - 1]]].push_back(tai[stk[top]]); tai[i] = tai[stk[top]]; r[tai[i]] = i, l[tai[i]] = stk[top]; top -- ; } } dfs(0); while (q--) { int a, b; scanf("%d%d", &a, &b); int lc = lca(tai[a], tai[b]); if (lc == 0) printf("-1\n"); else printf("%d %d\n", l[lc], r[lc]); } return 0; }