#include <bits/stdc++.h>
using namespace std;
long long int a[2000005], n;
struct node {
  long long int nb_left, nb_right, long_max;
  node() { nb_left = 0, nb_right = 0, long_max = 0; }
  node(long long int val, long long int flag) {
    if (flag) {
      if (val == 1) {
        nb_left = 0;
        nb_right = 1;
        long_max = 0;
      } else if (val == -1) {
        nb_left = 1;
        nb_right = 0;
        long_max = 0;
      }
    } else {
      nb_left = 0;
      nb_right = 0;
      long_max = 0;
    }
  }
  void merge(node left, node right) {
    nb_left = left.nb_left + right.nb_left;
    nb_right = left.nb_right + right.nb_right;
    long_max = left.long_max + right.long_max;
    long long int rest_left = 0, rest_right = 0;
    if (left.nb_left) rest_left = left.nb_left - (left.long_max / 2);
    if (right.nb_right) rest_right = right.nb_right - (right.long_max / 2);
    long_max += min(rest_left, rest_right) * 2;
  }
} tree[10000005];
void build(long long int nod, long long int start, long long int end) {
  if (start == end) {
    tree[nod] = node(a[start], 1);
  } else {
    long long int mid = (start + end) / 2;
    build(2 * nod, start, mid);
    build(2 * nod + 1, mid + 1, end);
    tree[nod].merge(tree[2 * nod], tree[2 * nod + 1]);
  }
}
void update(long long int nod, long long int start, long long int end,
            long long int idx, long long int val) {
  if (end == start) {
    a[idx] = val;
    tree[nod] = node(val, 1);
  } else {
    long long int mid = (start + end) / 2;
    if (idx >= start && idx <= mid)
      update(2 * nod, start, mid, idx, val);
    else
      update(2 * nod + 1, mid + 1, end, idx, val);
    tree[nod].merge(tree[2 * nod], tree[2 * nod + 1]);
  }
}
node query(long long int nod, long long int start, long long int end,
           long long int l, long long int r) {
  if (r < start or l > end) {
    node p(0, 0);
    return p;
  }
  if (l <= start && r >= end) return tree[nod];
  long long int mid = (start + end) / 2;
  node q1, q2, parent = node();
  q1 = query(2 * nod, start, mid, l, r);
  q2 = query(2 * nod + 1, mid + 1, end, l, r);
  parent.merge(q1, q2);
  return parent;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long int i, j, nb = 0, l, r, e, q, m;
  char k;
  string s;
  cin >> s;
  n = s.size();
  for (i = 1; i <= n; i++) {
    k = s[i - 1];
    if (k == '(')
      a[i] = -1;
    else
      a[i] = 1;
  }
  build(1, 1, n);
  cin >> q;
  while (q--) {
    cin >> l >> r;
    cout << query(1, 1, n, l, r).long_max << endl;
  }
}
