#include <bits/stdc++.h>
using namespace std;
const int sz = (1 << 20) - 1;
int a[sz * 2], b[sz * 2], c[sz * 2];
void upd(int v, char ch) {
  v += sz;
  if (ch == '(') {
    ++a[v];
  } else {
    ++c[v];
  }
  while ((v /= 2) >= 1) {
    b[v] = b[v + v] + b[v * 2 + 1];
    int mn = min(a[v + v], c[v + v + 1]);
    b[v] += mn;
    a[v] = a[v * 2] + a[v * 2 + 1] - mn;
    c[v] = c[v * 2] + c[v * 2 + 1] - mn;
  }
}
int get(int l, int r) {
  int res = 0, sum = 0;
  stack<int> st;
  for (l += sz, r += sz; l <= r; l /= 2, r /= 2) {
    if (l % 2 == 1) {
      res += b[l];
      int mn = min(sum, c[l]);
      sum += a[l];
      res += mn;
      sum -= mn;
      ++l;
    }
    if (r % 2 == 0) st.push(r--);
    if (l > r) break;
  }
  while (int(st.size())) {
    int v = st.top();
    st.pop();
    res += b[v];
    int mn = min(sum, c[v]);
    sum += a[v];
    res += mn;
    sum -= mn;
  }
  return res * 2;
}
string s;
int l, r, q;
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  int n = int(s.size());
  for (int i = 0; i < n; ++i) {
    upd(i + 1, s[i]);
  }
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    cin >> l >> r;
    cout << get(l, r) << endl;
  }
  return 0;
}
