#include <bits/stdc++.h>
using namespace std;
char str[1000010];
int store[1000010];
class BIT {
 public:
  int N;
  long long tree[1000010];
  BIT(int a) { N = a; }
  void initialize(bool initialValuePresent = true) {
    if (!initialValuePresent) {
      memset(tree, 0, sizeof(0));
      return;
    }
  }
  int cumulativeQuery(int idx) {
    int sum = 0;
    while (idx > 0) {
      sum += tree[idx];
      idx -= (idx & -idx);
    }
    return sum;
  }
  void update(int idx, long long val) {
    while (idx <= N) {
      tree[idx] += val;
      idx += (idx & -idx);
    }
  }
};
int main() {
  scanf("%s", str);
  int n = strlen(str);
  int u, v, q;
  vector<pair<int, pair<int, int> > > lst;
  scanf("%d", &q);
  for (int i = 0; i < (int)(q); ++i) {
    scanf("%d%d", &u, &v);
    u--;
    v--;
    lst.push_back(make_pair(u, make_pair(v, i)));
  }
  sort(lst.begin(), lst.end());
  stack<int> st;
  memset(store, -1, sizeof(store));
  ;
  for (int i = 0; i < (int)(n); ++i) {
    if (str[i] == '(')
      st.push(i);
    else {
      if (!st.empty()) {
        store[st.top()] = i;
        st.pop();
      }
    }
  }
  vector<pair<int, int> > sol;
  int j = 0;
  BIT* bit = new BIT(n);
  for (int i = 0; i < (int)(n); ++i)
    if (store[i] != -1) bit->update(store[i] + 1, 1);
  for (int i = 0; i < (int)(q); ++i) {
    for (; j < lst[i].first; ++j) {
      if (store[j] != -1) bit->update(store[j] + 1, -1);
    }
    sol.push_back(make_pair(lst[i].second.second,
                            bit->cumulativeQuery(lst[i].second.first + 1) -
                                bit->cumulativeQuery(lst[i].first)));
  }
  sort(sol.begin(), sol.end());
  for (int i = 0; i < (int)(q); ++i) printf("%d\n", sol[i].second * 2);
  return 0;
}
