#include <bits/stdc++.h>
using namespace std;
int m;
char par[1000006], Val;
int Poz, inc, sf;
int t[2100001];
int o[2100001];
int c[2100001];
int solT, solO, solC;
int min(int a, int b) {
  if (a < b) return a;
  return b;
}
void actualizare(int nod, int st, int dr) {
  if (st == dr) {
    if (Val == '(')
      o[nod] = 1;
    else if (Val == ')')
      c[nod] = 1;
    return;
  } else {
    int mij = st + (dr - st) / 2;
    if (Poz <= mij)
      actualizare(2 * nod, st, mij);
    else
      actualizare(2 * nod + 1, mij + 1, dr);
  }
  int tmp = min(o[2 * nod], c[2 * nod + 1]);
  t[nod] = t[2 * nod] + t[2 * nod + 1] + tmp;
  o[nod] = o[2 * nod] + o[2 * nod + 1] - tmp;
  c[nod] = c[2 * nod] + c[2 * nod + 1] - tmp;
}
void interogare(int nod, int st, int dr) {
  if (inc <= st && dr <= sf) {
    solT += t[nod];
    solC = c[nod];
    int tmp = min(solC, solO);
    solT += tmp;
    solO -= tmp;
    solO += o[nod];
    return;
  } else {
    int mij = st + (dr - st) / 2;
    if (inc <= mij) interogare(2 * nod, st, mij);
    if (mij + 1 <= sf) interogare(2 * nod + 1, mij + 1, dr);
  }
}
int main() {
  cin >> par;
  int len = strlen(par);
  for (int i = 0; i < len; ++i) {
    Val = par[i], Poz = i + 1;
    actualizare(1, 1, len);
  }
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> inc >> sf;
    solT = solO = solC = 0;
    interogare(1, 1, len);
    cout << 2 * solT << "\n";
  }
  return 0;
}
