from atcoder.segtree import SegTree N, Q = map(int, input().split()) S = "(" + input() + ")" INF = N dicpair = {} prs = [] # pairs st = [] # stack lv = 0 X = [0] * (N + 3) for i, s in enumerate(S): if s == "(": st.append(i) X[i + 1] = X[i] + 1 else: X[i + 1] = X[i] - 1 j = st.pop() dicpair[i] = j dicpair[j] = i prs.append((j, i)) st = SegTree(min, INF, X) prs.sort() dic = {} for i, (pa, pb) in enumerate(prs): dic[pa] = i for _ in range(Q): a, c = map(int, input().split()) b = dicpair[a] if a > b: a, b = b, a d = dicpair[c] if c > d: c, d = d, c if a > c: a, c = c, a b, d = d, a if a <= c and d <= b: print(a, b) continue btm = st.prod(b, d) aa = st.min_left(a, lambda v: v >= btm) dd = st.max_right(d, lambda v: v >= btm) if aa == 1: print(-1) else: print(aa-1,dd-1)