#include <bits/stdc++.h>
using namespace std;
int n, m, q1, q2, sag, sol;
char A[1000010];
pair<pair<int, int>, int> D[1000005 * 4];
pair<pair<int, int>, int> find(int k, int a, int b) {
  if (q1 > b || q2 < a)
    return pair<pair<int, int>, int>(pair<int, int>(0, 0), 0);
  if (q1 <= a && b <= q2) return D[k];
  pair<pair<int, int>, int> s1, s2;
  s1 = find(2 * k, a, (a + b) / 2);
  s2 = find(2 * k + 1, (a + b) / 2 + 1, b);
  return pair<pair<int, int>, int>(
      pair<int, int>(
          s2.first.first + max(0, s1.first.first - s2.first.second),
          s1.first.second + (-1 * min(0, s1.first.first - s2.first.second))),
      s1.second + s2.second + 2 * min(s1.first.first, s2.first.second));
}
pair<pair<int, int>, int> olustur(int k, int a, int b) {
  if (a == b && A[a] == '(')
    return D[k] = pair<pair<int, int>, int>(pair<int, int>(1, 0), 0);
  if (a == b && A[a] == ')')
    return D[k] = pair<pair<int, int>, int>(pair<int, int>(0, 1), 0);
  pair<pair<int, int>, int> s1 = olustur(2 * k, a, (a + b) / 2),
                            s2 = olustur(2 * k + 1, (a + b) / 2 + 1, b);
  return D[k] = pair<pair<int, int>, int>(
             pair<int, int>(
                 s2.first.first + max(0, s1.first.first - s2.first.second),
                 s1.first.second +
                     (-1 * min(0, s1.first.first - s2.first.second))),
             s1.second + s2.second + 2 * min(s1.first.first, s2.first.second));
}
int main() {
  scanf("%s", A + 1);
  n = (int)strlen(A + 1);
  olustur(1, 1, n);
  scanf("%d", &m);
  for (int j = 1; j <= m; j++) {
    sag = 0;
    sol = 0;
    scanf("%d %d", &q1, &q2);
    printf("%d\n", find(1, 1, n).second);
  }
}
