#include <bits/stdc++.h>
using namespace std;
struct Node {
  int len, no, nc;
} tree[4000010];
string str;
void update(int pos, int idx = 0, int L = 0, int R = ((int)str.size()) - 1) {
  Node &ref = tree[idx];
  if (L == R) {
    ref.len = 0, ref.no = 1 - (str[pos] == '('), ref.nc = 1 - (str[pos] == ')');
  } else {
    int nL = (idx << 1) + 1, nR = nL + 1, mid = (L + R) >> 1;
    if (pos <= mid)
      update(pos, nL, L, mid);
    else
      update(pos, nR, mid + 1, R);
    int tmp = min(tree[nL].nc, tree[nR].no);
    ref.len = tree[nL].len + tree[nR].len + tmp;
    ref.no = tree[nL].no + tree[nR].no - tmp;
    ref.nc = tree[nL].nc + tree[nR].nc - tmp;
  }
}
Node query(int i, int j, int idx = 0, int L = 0,
           int R = ((int)str.size()) - 1) {
  Node ret = {-1, -1, -1};
  if (L > j || R < i) return ret;
  if (L >= i && R <= j) return tree[idx];
  int nL = (idx << 1) + 1, nR = nL + 1, mid = (L + R) >> 1;
  Node p1 = query(i, j, nL, L, mid);
  Node p2 = query(i, j, nR, mid + 1, R);
  if (p1.len == -1) return p2;
  if (p2.len == -1) return p1;
  int tmp = min(p1.nc, p2.no);
  ret.len = p1.len + p2.len + tmp;
  ret.no = p1.no + p2.no - tmp;
  ret.nc = p1.nc + p2.nc - tmp;
  return ret;
}
int main() {
  cin >> str;
  for (int i = 0; i < ((int)str.size()); i++) update(i);
  int Q, a, b;
  cin >> Q;
  while (Q--) {
    cin >> a >> b;
    a--, b--;
    cout << (query(a, b).len) * 2 << endl;
  }
  return 0;
}
