#include <bits/stdc++.h>
using namespace std;
char s[2000005];
struct Node {
  int top1, top2, num;
  Node() {
    top1 = 0;
    top2 = 0;
    num = 0;
  }
  Node operator+(const Node &b) const {
    int d = min(top1, b.top2);
    Node ans;
    ans.num = num + b.num + d;
    ans.top1 = b.top1 + top1 - d;
    ans.top2 = b.top2 + top2 - d;
    return ans;
  }
};
inline int nextInt(int &w) {
  w = 0;
  register char ch = getchar();
  while ((ch < '0' || ch > '9')) ch = getchar();
  while (ch >= '0' && ch <= '9') w = w * 10 + ch - '0', ch = getchar();
  return w;
}
inline void Out(int a) {
  if (a > 9) Out(a / 10);
  putchar(a % 10 + '0');
}
const int MAXN = 2200000;
struct Segment_tree {
  int size;
  Node node[MAXN];
  void update(int pos) { node[pos] = node[pos + pos] + node[pos + pos + 1]; }
  void build(int n) {
    n += 4;
    size = 1;
    while (size < n) size <<= 1;
    memset(node, 0, sizeof(node));
  }
  void build(int n, char arr[]) {
    build(n);
    int i;
    for (i = 1; i <= n; i++) {
      if (s[i] == '(')
        node[i + size].top1 = 1;
      else {
        node[i + size].top2 = 1;
      }
    }
    for (i = size - 1; i > 0; i--) {
      update(i);
    }
  }
  int query(int l, int r) {
    l += size - 1;
    r += size + 1;
    Node lans, rans, ans;
    for (; l ^ r ^ 1; l >>= 1, r >>= 1) {
      if (~l & 1) lans = lans + node[l ^ 1];
      if (r & 1) rans = node[r ^ 1] + rans;
    }
    ans = lans + rans;
    return ans.num;
  }
} tree;
int main() {
  int n, m, k, len, moda, l, r, a, b;
  scanf("%s", s + 1);
  int i, j, ans, top, top2, mod;
  len = strlen(s + 1);
  tree.build(len, s + 1);
  scanf("%d", &m);
  while (m--) {
    nextInt(l);
    nextInt(r);
    Out(tree.query(l, r) * 2);
    putchar('\n');
  }
  return 0;
}
