#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
inline T max(T &a, U &b) {
  return a > b ? a : b;
}
template <class T, class U>
inline T min(T &a, U &b) {
  return a < b ? a : b;
}
template <class T, class U>
inline T swap(T &a, U &b) {
  T tmp = a;
  a = b;
  b = tmp;
}
const long long INF = (500000LL * 1000000000LL) + 7LL;
const int mx = 1e6 + 7;
const double pi = 2 * acos(0.0);
int EQ(double d) {
  if (fabs(d) < 1e-7) return 0;
  return d > 1e-7 ? 1 : -1;
}
int A[mx << 2];
void update(int lf, int rt, int idx, int x) {
  if (lf == x && rt == x) {
    A[idx]++;
    return;
  }
  int mid = (lf + rt) >> 1;
  if (x <= mid)
    update(lf, mid, idx * 2, x);
  else
    update(mid + 1, rt, idx * 2 + 1, x);
  A[idx] = A[idx * 2] + A[idx * 2 + 1];
}
int query(int lf, int rt, int idx, int x, int y) {
  if (x > y) return 0;
  if (lf >= x && rt <= y) {
    return A[idx];
  }
  int mid = (lf + rt) >> 1, ret = 0;
  if (x <= mid) ret += query(lf, mid, idx * 2, x, y);
  if (y > mid) ret += query(mid + 1, rt, idx * 2 + 1, x, y);
  return ret;
}
stack<int> s;
struct node {
  int x, y, id;
} a[mx];
int ans[mx];
bool cmp(node a, node b) { return (a.y < b.y || (a.y == b.y && a.x < b.x)); }
int main() {
  string st;
  cin >> st;
  int len = st.size(), cnt = 0;
  int q = ({
    int a;
    scanf("%d", &a);
    a;
  });
  for (__typeof((q)-1) i = (0); i <= ((q)-1); ++i) {
    int x = ({
      int a;
      scanf("%d", &a);
      a;
    }),
        y = ({
          int a;
          scanf("%d", &a);
          a;
        });
    a[i].x = x, a[i].y = y, a[i].id = i;
  }
  sort(a, a + q, cmp);
  for (__typeof((len)-1) i = (0); i <= ((len)-1); ++i) {
    if (st[i] == '(')
      s.push(i);
    else if (!s.empty()) {
      update(0, len, 1, s.top() + 1);
      s.pop();
    }
    while (cnt < q && a[cnt].y <= i + 1) {
      ans[a[cnt].id] = 2 * (query(0, len, 1, 0, a[cnt].y) -
                            query(0, len, 1, 0, a[cnt].x - 1));
      cnt++;
    }
    if (cnt == q) break;
  }
  for (__typeof((q)-1) i = (0); i <= ((q)-1); ++i) cout << ans[i] << endl;
}
