#include <bits/stdc++.h>
using namespace std;
int b1[] = {0, 0, 1, -1};
int b2[] = {1, -1, 0, 0};
int d1[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int d2[] = {-1, 0, 1, -1, 1, -1, 0, 1};
string st;
const int mxn = 1e6;
struct tp {
  int tt, cl, op;
} tree[4 * mxn];
void build_tree(int s, int e, int index) {
  tp obj;
  obj.tt = obj.cl = obj.op = 0;
  if (s == e) {
    obj.cl = (st[s] == ')');
    obj.op = (st[s] == '(');
    tree[index] = obj;
    return;
  }
  int mid = (s + e) / 2;
  build_tree(s, mid, 2 * index);
  build_tree(mid + 1, e, 2 * index + 1);
  int min_blnc = min(tree[2 * index].op, tree[2 * index + 1].cl);
  obj.tt = tree[2 * index].tt + tree[2 * index + 1].tt + 2 * min_blnc;
  obj.cl = tree[2 * index].cl + tree[2 * index + 1].cl - min_blnc;
  obj.op = tree[2 * index].op + tree[2 * index + 1].op - min_blnc;
  tree[index] = obj;
  return;
}
tp query(int second, int se, int qs, int qe, int index) {
  tp obj;
  obj.tt = obj.cl = obj.op = 0;
  if (second >= qs and se <= qe) {
    return tree[index];
  }
  if (qe < second || qs > se) return obj;
  int mid = (second + se) / 2;
  tp tp1 = query(second, mid, qs, qe, 2 * index);
  tp tp2 = query(mid + 1, se, qs, qe, 2 * index + 1);
  int min_blnc = min(tp1.op, tp2.cl);
  obj.tt = tp1.tt + tp2.tt + 2 * min_blnc;
  obj.cl = tp1.cl + tp2.cl - min_blnc;
  obj.op = tp1.op + tp2.op - min_blnc;
  return obj;
}
void solve() {
  cin >> st;
  int n = st.length();
  build_tree(0, n - 1, 1);
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    tp res = query(0, n - 1, x, y, 1);
    cout << res.tt << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
