#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
int f[MAXN];
void add(int val, int index) {
  for (int i = index; i < MAXN; i = (i | (i + 1))) {
    f[i] += val;
  }
}
int getAns(int x) {
  int ans = 0;
  for (int i = x; i >= 0; i = (i & (i + 1)) - 1) {
    ans += f[i];
  }
  return ans;
}
bool cmp(const tuple<int, int, int> &a, const tuple<int, int, int> &b) {
  return get<1>(a) < get<1>(b) ||
         (get<1>(a) == get<1>(b) && get<0>(a) < get<0>(b));
}
void solve() {
  string s;
  cin >> s;
  int n = s.size();
  deque<pair<char, int>> q;
  int a[n];
  memset(a, 255, sizeof(a));
  for (int i = 0; i < n; i++) {
    if (!q.empty() && q.back().first == '(' && s[i] == ')') {
      a[i] = q.back().second;
      q.pop_back();
    } else {
      q.emplace_back(make_pair(s[i], i));
    }
  }
  int m;
  cin >> m;
  tuple<int, int, int> request[m];
  for (int i = 0; i < m; i++) {
    int L, R;
    cin >> L >> R;
    request[i] = make_tuple(L - 1, R - 1, i);
  }
  sort(request, request + m, cmp);
  int now = -1, ans[m];
  for (int i = 0; i < m; i++) {
    int L = get<0>(request[i]), R = get<1>(request[i]), id = get<2>(request[i]);
    while (now <= R - 1) {
      now++;
      if (a[now] != -1) {
        add(1, a[now] + 1);
      }
    }
    ans[id] = (getAns(R) - getAns(L)) * 2;
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i] << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  solve();
}
