#include <bits/stdc++.h>
using namespace std;
const int p = (1 << 20);
int d[2 * p];
int pref[p];
int pref_b[p];
int pref_e[p];
const int INF = 1000000000;
void wstaw(int pos, int x) {
  pos += p;
  d[pos] = x;
  pos >>= 1;
  while (pos > 0) {
    d[pos] = min(d[pos * 2], d[2 * pos + 1]);
    pos >>= 1;
  }
}
int query(int l, int r) {
  l += p;
  r += p;
  int wyn = min(d[l], d[r]);
  while (l < r) {
    if (l & 1) wyn = min(wyn, d[l++]);
    if (!(r & 1)) wyn = min(wyn, d[r--]);
    l >>= 1;
    r >>= 1;
  }
  if (l == r) wyn = min(wyn, d[l]);
  return wyn;
}
int main() {
  for (int i = 0; i < 2 * p; i++) d[i] = INF;
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  pref[0] = 0;
  pref_b[0] = 0;
  pref_e[0] = 0;
  int n = s.size();
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == '(') {
      pref[i] = pref[i - 1] + 1;
      pref_b[i] = pref_b[i - 1] + 1;
      pref_e[i] = pref_e[i - 1];
      wstaw(i, pref[i]);
    } else {
      pref[i] = pref[i - 1] - 1;
      pref_b[i] = pref_b[i - 1];
      pref_e[i] = pref_e[i - 1] + 1;
      wstaw(i, pref[i]);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    int mini = query(l, r);
    int nadmiar = max(0, (pref[l - 1] - mini));
    int naw = max(0, pref_e[r] - pref_e[l - 1] - nadmiar);
    cout << 2 * naw << "\n";
  }
  return 0;
}
