#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 6;
string s;
long long opene[N], close[N], ans[N], m;
const pair<long long, pair<long long, long long> > zero = {0, {0, 0}};
void segment(long long l, long long r, long long num) {
  if (r - l <= 1) {
    if (s[l] == ')')
      close[num] = 1;
    else
      opene[num] = 1;
    return;
  }
  long long mid = (l + r) / 2;
  segment(l, mid, 2 * num);
  segment(mid, r, 2 * num + 1);
  long long add = min(opene[2 * num], close[2 * num + 1]);
  opene[num] = opene[2 * num] + opene[2 * num + 1] - add;
  close[num] = close[2 * num] + close[2 * num + 1] - add;
  ans[num] = ans[2 * num] + ans[2 * num + 1] + add;
}
pair<long long, pair<long long, long long> > solve(long long x, long long y,
                                                   long long l, long long r,
                                                   long long num) {
  pair<long long, pair<long long, long long> > Ans = zero;
  if (l >= y || x >= r) return zero;
  if (x <= l && r <= y)
    return pair<long long, pair<long long, long long> >(
        ans[num], {opene[num], close[num]});
  long long mid = (l + r) / 2;
  pair<long long, pair<long long, long long> > Left =
      solve(x, y, l, mid, 2 * num);
  pair<long long, pair<long long, long long> > Righ =
      solve(x, y, mid, r, 2 * num + 1);
  long long add = min(Left.second.first, Righ.second.second);
  long long F = add + Left.first + Righ.first;
  long long FF = Righ.second.first + Left.second.first - add;
  long long FS = Righ.second.second + Left.second.second - add;
  Ans = {F, {FF, FS}};
  return Ans;
}
int main(int argc, const char* argv[]) {
  getline(cin, s);
  long long n = (long long)s.length();
  segment(0, n, 1);
  scanf("%I64d", &m);
  for (long long i = 0; i < m; i++) {
    long long c, r;
    scanf("%I64d", &c);
    scanf("%I64d", &r);
    pair<long long, pair<long long, long long> > x = solve(c - 1, r, 0, n, 1);
    printf("%I64d\n", x.first * 2);
  }
  return 0;
}
