#include <bits/stdc++.h>
using namespace std;
struct segment_tree {
  vector<pair<int, pair<int, int> > > st;
  string S;
  int n;
  segment_tree(string s) : st(4 * (int)s.size() + 5), S(s), n((int)s.size()) {
    build(1, 0, n - 1);
  }
  pair<int, pair<int, int> > merge(pair<int, pair<int, int> > l,
                                   pair<int, pair<int, int> > r) {
    int a1 = l.first;
    int b1 = l.second.first;
    int c1 = l.second.second;
    int a2 = r.first;
    int b2 = r.second.first;
    int c2 = r.second.second;
    int t = min(b1, c2);
    pair<int, pair<int, int> > ans;
    ans.first = a1 + a2 + t;
    ans.second.first = b1 + b2 - t;
    ans.second.second = c1 + c2 - t;
    return ans;
  }
  void build(int node, int b, int e) {
    if (b == e) {
      int A = 0, B = 0, C = 0;
      if (S[b] == '(')
        B++;
      else
        C++;
      st[node] = {A, {B, C}};
    } else {
      int m = (b + e) >> 1;
      int l = 2 * node;
      int r = 2 * node + 1;
      build(l, b, m);
      build(r, m + 1, e);
      st[node] = merge(st[l], st[r]);
    }
  }
  pair<int, pair<int, int> > query(int node, int b, int e, int i, int j) {
    if (b >= i && e <= j) return st[node];
    if (i > e || j < b) return {0, {0, 0}};
    int m = (b + e) >> 1;
    int l = 2 * node;
    int r = 2 * node + 1;
    pair<int, pair<int, int> > left = query(l, b, m, i, j);
    pair<int, pair<int, int> > right = query(r, m + 1, e, i, j);
    pair<int, pair<int, int> > ans = merge(left, right);
    return ans;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  segment_tree st(s);
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    pair<int, pair<int, int> > S = st.query(1, 0, st.n - 1, l, r);
    cout << 2 * S.first << '\n';
  }
  return 0;
}
