import scala.annotation.tailrec import scala.collection.immutable import scala.collection.immutable.TreeSet import scala.io.StdIn.readLine import scala.math.* @main def main = 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){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)