#include <bits/stdc++.h>
using namespace std;
int n, Q;
const int N = 1000002;
char str[N];
pair<pair<int, int>, int> seg[4 * N];
pair<pair<int, int>, int> combine(pair<pair<int, int>, int> c1,
                                  pair<pair<int, int>, int> c2) {
  pair<pair<int, int>, int> ret;
  int can_make = min(c1.first.first, c2.first.second);
  ret.first.first = c1.first.first - can_make + c2.first.first;
  ret.first.second = c2.first.second - can_make + c1.first.second;
  ret.second = c1.second + c2.second + can_make;
  return ret;
}
void build(int indx, int l, int r) {
  if (l == r) {
    seg[indx].first.first = str[l] == '(';
    seg[indx].first.second = str[l] == ')';
    seg[indx].second = 0;
  } else {
    build(indx * 2, l, (l + r) / 2);
    build(indx * 2 + 1, (l + r) / 2 + 1, r);
    seg[indx] = combine(seg[indx * 2], seg[indx * 2 + 1]);
  }
}
pair<pair<int, int>, int> answer(int indx, int l, int r, int i, int j) {
  if (l > j || r < i) return {{0, 0}, 0};
  if (i <= l && j >= r) {
    return seg[indx];
  }
  return combine(answer(indx * 2, l, (l + r) / 2, i, j),
                 answer(indx * 2 + 1, (l + r) / 2 + 1, r, i, j));
}
int main() {
  scanf("%s %d", str, &Q);
  n = strlen(str);
  build(1, 0, n - 1);
  while (Q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    l--, r--;
    printf("%d\n", 2 * answer(1, 0, n - 1, l, r).second);
  }
  return 0;
}
