#include typedef struct Edge { struct Edge *next; int v; } edge; int par[200003][20]; int main() { int i, N, Q; char S[200003]; scanf("%d %d", &N, &Q); scanf("%s", S); int u, w, M = 0, stack[200003], head = 0, indeg[200003] = {}, mate[200003], flag[200003]; edge *adj[200003] = {}, e[200003], *p; for (i = 0; i < N; i++) { if (S[i] == '(') stack[head++] = i + 1; else { head--; mate[i+1] = stack[head]; mate[stack[head]] = i + 1; flag[i+1] = -1; flag[stack[head]] = 1; if (head == 0) continue; u = stack[head-1]; w = stack[head]; e[M].v = w; e[M].next = adj[u]; adj[u] = &(e[M++]); indeg[w]++; } } int j, x, depth[200003], q[200003], tail; for (i = 1, depth[0] = -1; i <= N; i++) { if (indeg[i] != 0 || flag[i] < 0) continue; q[0] = i; depth[i] = 0; par[i][0] = 0; for (head = 0, tail = 1; head < tail; head++) { u = q[head]; for (p = adj[u]; p != NULL; p = p->next) { w = p->v; depth[w] = depth[u] + 1; par[w][0] = u; for (j = 1, x = par[u][0]; x != 0; par[w][j] = x, x = par[x][j++]); par[w][j] = 0; q[tail++] = w; } } } for (i = 1; i <= Q; i++) { scanf("%d %d", &u, &w); if (flag[u] < 0) u = mate[u]; if (flag[w] < 0) w = mate[w]; while (depth[u] > depth[w]) { for (j = 0; depth[par[u][j+1]] >= depth[w]; j++); u = par[u][j]; } while (depth[w] > depth[u]) { for (j = 0; depth[par[w][j+1]] >= depth[u]; j++); w = par[w][j]; } while (u != w) { for (j = 0; par[u][j+1] != par[w][j+1]; j++); u = par[u][j]; w = par[w][j]; } if (u != 0) printf("%d %d\n", u, mate[u]); else printf("-1\n"); } fflush(stdout); return 0; }