#include <bits/stdc++.h>
using namespace std;
long long int t[4000002];
long long int o[4000002];
long long int c[4000002];
string s;
void build(long long int ind, long long int l, long long int r) {
  if (r - l == 0) {
    t[ind] = 0;
    if (s[l] == '(')
      o[ind] = 1;
    else
      c[ind] = 1;
  } else {
    long long int mid = (l + r) / 2;
    build(2 * ind, l, mid);
    build(2 * ind + 1, mid + 1, r);
    long long int var = min(o[2 * ind], c[2 * ind + 1]);
    t[ind] = t[2 * ind] + t[2 * ind + 1] + var;
    o[ind] = o[2 * ind] + o[2 * ind + 1] - var;
    c[ind] = c[2 * ind] + c[2 * ind + 1] - var;
  }
}
pair<long long int, pair<long long int, long long int> > query(
    long long int ind, long long int l, long long int r, long long int from,
    long long int to) {
  if (to < l || from > r) {
    return make_pair(0, make_pair(0, 0));
  }
  if (from <= l && to >= r) {
    return make_pair(t[ind], make_pair(o[ind], c[ind]));
  }
  long long int mid = (l + r) / 2;
  pair<long long int, pair<long long int, long long int> > ltchild =
      query(2 * ind, l, mid, from, to);
  pair<long long int, pair<long long int, long long int> > rtchild =
      query(2 * ind + 1, mid + 1, r, from, to);
  long long int temp = min(ltchild.second.first, rtchild.second.second);
  long long int t = ltchild.first + rtchild.first + temp;
  long long int o = ltchild.second.first + rtchild.second.first - temp;
  long long int c = ltchild.second.second + rtchild.second.second - temp;
  return make_pair(t, make_pair(o, c));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, i, j, p, q, ans = 0, cnt = 0;
  cin >> s;
  cin >> q;
  n = s.length();
  build(1, 0, n - 1);
  while (q--) {
    cin >> i >> j;
    i--;
    j--;
    pair<long long int, pair<long long int, long long int> > an =
        query(1, 0, n - 1, i, j);
    cout << an.first * 2 << endl;
  }
  return 0;
}
