#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 9;
class SegmentTree {
 private:
  vector<pair<int, int> > st;
  vector<char> A;
  int n;
  int left(int p) { return (p << 1); }
  int right(int p) { return (p << 1) + 1; }
  void build(int p, int L, int R) {
    if (L == R) {
      if (A[L] == '(')
        st[p] = make_pair(1, 0);
      else
        st[p] = make_pair(0, 1);
    } else {
      build(left(p), L, (L + R) / 2);
      build(right(p), (L + R) / 2 + 1, R);
      pair<int, int> p1 = st[left(p)], p2 = st[right(p)];
      int aux = min(p1.first, p2.second);
      st[p] = make_pair(p1.first + p2.first - aux, p1.second + p2.second - aux);
    }
  }
  pair<int, int> rmq(int p, int L, int R, int i, int j) {
    if (i > R || j < L) return make_pair(-1, -1);
    if (L >= i && R <= j) return st[p];
    pair<int, int> p1 = rmq(left(p), L, (L + R) / 2, i, j);
    pair<int, int> p2 = rmq(right(p), (L + R) / 2 + 1, R, i, j);
    if (p1.first == -1) return p2;
    if (p2.first == -1) return p1;
    int aux = min(p1.first, p2.second);
    return make_pair(p1.first + p2.first - aux, p1.second + p2.second - aux);
  }
  void update(int p, int L, int R, int i) {
    if (i < L || i > R) return;
    if (L == R) {
      swap(st[p].first, st[p].second);
      return;
    }
    update(left(p), L, (L + R) / 2, i);
    update(right(p), (L + R) / 2 + 1, R, i);
    pair<int, int> p1 = st[left(p)], p2 = st[right(p)];
    int aux = min(p1.first, p2.second);
    st[p] = make_pair(p1.first + p2.first - aux, p1.second + p2.second - aux);
  }

 public:
  SegmentTree(const vector<char> &_A) {
    A = _A;
    n = A.size();
    st.assign(4 * n, make_pair(0, 0));
    build(1, 0, n - 1);
  }
  pair<int, int> rmq(int i, int j) { return rmq(1, 0, n - 1, i, j); }
  void update(int i) { update(1, 0, n - 1, i); }
};
int main() {
  string s;
  cin >> s;
  vector<char> V((int)(s.size()));
  for (int i = 0; i < (int)((int)(s.size())); i++) V[i] = s[i];
  SegmentTree st(V);
  int N;
  scanf("%d", &N);
  int a, b;
  for (int i = 0; i < (int)(N); i++) {
    scanf("%d %d", &a, &b);
    pair<int, int> aux = st.rmq(a - 1, b - 1);
    cout << b - a + 1 - aux.first - aux.second << endl;
  }
  return 0;
}
