#include <bits/stdc++.h>
using namespace std;
char str[1000006];
struct ss {
  int st, nd, idx, ans;
} queries[100006];
vector<int> TREE[4 * 1000006];
bool cmp2(ss a, ss b) { return a.nd < b.nd; }
bool cmp3(ss a, ss b) { return a.idx < b.idx; }
vector<pair<int, int> > V;
int BIT[1000006];
void update(int N, int idx) {
  while (idx <= N) {
    ++BIT[idx];
    idx += idx & -idx;
  }
}
int query(int idx) {
  int ret = 0;
  while (idx > 0) {
    ret += BIT[idx];
    idx -= idx & -idx;
  }
  return ret;
}
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) return a.second < b.second;
  return a.first < b.first;
}
int main() {
  stack<int> S;
  int i, n, v, Q, q, N;
  while (scanf("%s", str + 1) != EOF) {
    N = strlen(str + 1);
    while (!S.empty()) S.pop();
    for (i = 1; i <= N; ++i) {
      if (str[i] == '(') {
        S.push(i);
        continue;
      }
      if (S.empty()) continue;
      n = S.top();
      S.pop();
      V.push_back(make_pair(n, i));
    }
    sort(V.begin(), V.end(), cmp);
    v = 0;
    scanf("%d", &Q);
    for (i = 0; i < Q; ++i) {
      scanf("%d %d", &queries[i].st, &queries[i].nd);
      queries[i].idx = i;
    }
    sort(queries, queries + Q, cmp2);
    v = q = 0;
    memset(BIT, 0, sizeof(BIT));
    while (q < Q) {
      while (v < V.size() && V[v].second <= queries[q].nd) {
        update(N, V[v].first);
        ++v;
      }
      queries[q].ans = query(queries[q].nd) - query(queries[q].st - 1);
      ++q;
    }
    sort(queries, queries + Q, cmp3);
    for (q = 0; q < Q; ++q) printf("%d\n", queries[q].ans * 2);
  }
  return 0;
}
