#include <bits/stdc++.h>
using namespace std;
struct wie {
  int dl, otw, zam;
};
vector<wie> T;
int l, size;
wie Merguj(wie a, wie b) {
  int wsp = min(a.otw, b.zam);
  return {a.dl + b.dl + 2 * wsp, a.otw + b.otw - wsp, a.zam + b.zam - wsp};
}
void Stworz(int n, string s) {
  int p = 1;
  while (p < n) p *= 2;
  l = p;
  size = 2 * p - 1;
  for (int i = 0; i <= size; ++i) T.push_back({0, 0, 0});
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '(')
      T[i + l] = {0, 1, 0};
    else
      T[i + l] = {0, 0, 1};
  }
  for (int i = l - 1; i >= 1; --i) T[i] = Merguj(T[2 * i], T[2 * i + 1]);
}
int Pyt(int a, int b) {
  a += l;
  b += l;
  vector<wie> L, P;
  L.push_back(T[a]);
  if (a != b) P.push_back(T[b]);
  while (a / 2 != b / 2) {
    if (a % 2 == 0) L.push_back(T[a + 1]);
    if (b % 2 == 1) P.push_back(T[b - 1]);
    a /= 2;
    b /= 2;
  }
  reverse(P.begin(), P.end());
  vector<wie> wsz;
  wsz = L;
  for (int i = 0; i < P.size(); ++i) wsz.push_back(P[i]);
  wie akt = wsz[0];
  for (int i = 1; i < wsz.size(); ++i) akt = Merguj(akt, wsz[i]);
  return akt.dl;
}
int main() {
  ios_base::sync_with_stdio(0);
  string a;
  cin >> a;
  int n = a.size();
  Stworz(n, a);
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    cout << Pyt(a - 1, b - 1) << endl;
  }
  return 0;
}
