#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
int n, c, l, r;
string s;
class st_node {
 public:
  int opening, closing, mx;
  void set(char bracket) {
    if (bracket == '(') {
      opening = 0;
      closing = 1;
      mx = 0;
    } else {
      opening = 1;
      closing = 0;
      mx = 0;
    }
  }
  void merge(st_node& l, st_node& r) {
    int common = min(r.opening, l.closing);
    opening = l.opening + r.opening - common;
    closing = r.closing + l.closing - common;
    mx = l.mx + r.mx + 2 * common;
  }
} node[4 * N];
void build(int idx, int l, int r) {
  if (l == r) {
    node[idx].set(s[l]);
  } else {
    int mid = l + r >> 1, lchild = idx << 1, rchild = lchild + 1;
    build(lchild, l, mid);
    build(rchild, mid + 1, r);
    node[idx].merge(node[lchild], node[rchild]);
  }
}
st_node query(int idx, int l, int r, int ql, int qr) {
  int mid = l + r >> 1, lchild = idx << 1, rchild = lchild + 1;
  if (l == ql && r == qr) {
    return node[idx];
  }
  if (ql > mid) {
    return query(rchild, mid + 1, r, ql, qr);
  }
  if (qr <= mid) {
    return query(lchild, l, mid, ql, qr);
  } else {
    st_node left = query(lchild, l, mid, ql, mid);
    st_node right = query(rchild, mid + 1, r, mid + 1, qr);
    st_node ans;
    ans.merge(left, right);
    return ans;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> s >> c;
  n = s.length();
  build(1, 0, n - 1);
  for (int i = 0; i < c; i++) {
    cin >> l >> r;
    cout << query(1, 0, n - 1, l - 1, r - 1).mx << "\n";
  }
  return 0;
}
