#include <bits/stdc++.h>
using namespace std;
struct st {
  int neg, pos;
  int ans;
  st() { neg = pos = ans = 0; };
} tree[3 * 1000006], q[3 * 1000006];
void merge(int x, st T[]) {
  T[x].ans = T[2 * x].ans + T[2 * x + 1].ans;
  int omar = min(T[2 * x].pos, T[2 * x + 1].neg);
  T[x].ans += 2 * omar;
  T[x].pos = T[2 * x].pos - omar + T[2 * x + 1].pos;
  T[x].neg = T[2 * x + 1].neg - omar + T[2 * x].neg;
}
char ar[1000006];
void init(int x, int a, int b) {
  if (a == b) {
    tree[x] = st();
    if (ar[a] == ')')
      tree[x].neg = 1;
    else
      tree[x].pos = 1;
    return;
  }
  init(2 * x, a, (a + b) / 2);
  init(2 * x + 1, (a + b) / 2 + 1, b);
  merge(x, tree);
}
int query(int x, int a, int b, int i, int j) {
  if (a > j || b < i) {
    q[x] = st();
    return 0;
  }
  if (i <= a && j >= b) {
    q[x].ans = tree[x].ans;
    q[x].neg = tree[x].neg;
    q[x].pos = tree[x].pos;
    return q[x].ans;
  }
  query(2 * x, a, (a + b) / 2, i, j);
  query(2 * x + 1, (a + b) / 2 + 1, b, i, j);
  merge(x, q);
  return q[x].ans;
}
int main() {
  scanf("%s", ar);
  int n = strlen(ar);
  int Q;
  int u, v;
  init(1, 0, n - 1);
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d", &u, &v);
    printf("%d\n", query(1, 0, n - 1, u - 1, v - 1));
  }
}
