#include <bits/stdc++.h>
using namespace std;
void read(long long a = 0) {
  freopen("in", "r", stdin);
  if (a) freopen("out", "w", stdout);
}
pair<long long, long long> seg[100 * 100009];
long long from, to;
pair<long long, long long> merge(pair<long long, long long> a,
                                 pair<long long, long long> b) {
  pair<long long, long long> ans;
  ans.first = a.first, ans.second = b.second;
  long long u = a.second, v = b.first;
  if (u == v)
    return ans;
  else if (u > v)
    ans.second += u - v;
  else
    ans.first += v - u;
  return ans;
}
string str;
pair<long long, long long> build(long long second = from, long long e = to,
                                 long long p = 1) {
  long long mid = (second + e) >> 1;
  if (second == e) {
    seg[p].first = (str[second] == ')');
    seg[p].second = (str[second] == '(');
    return seg[p];
  }
  return seg[p] =
             merge(build(second, mid, p << 1), build(mid + 1, e, p << 1 | 1));
}
pair<long long, long long> null;
pair<long long, long long> get(long long x, long long y,
                               long long second = from, long long e = to,
                               long long p = 1) {
  if (x <= second && y >= e)
    return seg[p];
  else if (x > e || second > y)
    return null;
  long long mid = (second + e) >> 1;
  return merge(get(x, y, second, mid, p << 1),
               get(x, y, mid + 1, e, p << 1 | 1));
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> str;
  from = 0, to = str.length() - 1;
  build();
  long long q;
  cin >> q;
  while (q--) {
    long long x, y;
    cin >> x >> y;
    pair<long long, long long> tmp = get(x - 1, y - 1);
    long long sum = tmp.first + tmp.second;
    cout << y - x + 1 - sum << "\n";
  }
}
