#include #include #include int MAX = 200020; int main() { int N, Q; std::string S; std::cin >> N >> Q >> S; int pair[MAX]; int left[MAX]; { int stack[MAX >> 1]; int len = 1; for (int i = 1;i <= S.length();++ i) { char c = S[i - 1]; if (c == '(') { stack[len++] = i; left[i] = left[i - 1] + 1; } else { pair[i] = stack[--len]; pair[pair[i]] = i; left[i] = left[i - 1]; } } } while(Q --> 0) { int x, y; std::cin >> x >> y; if (x < y) { int l = std::min(x, pair[x]); int r = std::max(y, pair[y]); x = l; y = r; } else { int l = std::min(y, pair[y]); int r = std::max(x, pair[x]); x = l; y = r; } for (int i = x;i >= 0; -- i) { if (pair[i] >= y) { std::cout << i << ' ' << pair[i] << std::endl; goto cont; } if (i >= 30 && left[i] - left[i - 30] == 30 && pair[i - 30] < y) i -= 30; } std::cout << -1 << std::endl; cont:; } return 0; }