import java.io.BufferedReader import scala.annotation.tailrec import scala.collection.{immutable, mutable} import scala.io.StdIn.readLine import scala.math.* import scala.annotation.tailrec import scala.io.{BufferedSource, Source, StdIn} def readLine()(using reader: BufferedReader): String = reader.readLine() @main def main = given reader: BufferedReader = Source.stdin.bufferedReader() val Array(n, q) = readLine().split(' ').map(_.toInt) val s = readLine() val queries = Array.fill(q){ val Array(x, y) = readLine().split(' ').map(_.toInt - 1) min(x, y) -> max(x, y) } var stack = Nil: List[Int] val pair = Array.fill(n){-1} for (c, i) <- s.zipWithIndex do c match case '(' => stack ::= i case ')' => val h::t = stack pair(i) = h pair(h) = i stack = t val set = Array.fill(n){immutable.TreeSet[Int]()} for i <- 0 until n do if i > 0 then set(i) = set(i - 1) if s(i) == '(' then set(i) = set(i) + pair(i) for (x, y) <- queries do val result = set(x).minAfter(y).map(right => s"${pair(right) + 1} ${right + 1}").getOrElse("-1") println(result)