#include <bits/stdc++.h>
using namespace std;
int const N = 1000100;
struct Node {
  int lf, rg;
  int res;
  Node *l, *r;
  Node() { lf = rg = res = 0; }
  Node(char ch) {
    lf = (ch == '(');
    rg = (ch == ')');
    res = 0;
  }
};
Node* comb(Node* b, Node* c, Node* a = new Node()) {
  int add = min(b->lf, c->rg);
  a->res = b->res + c->res + add;
  a->lf = b->lf + c->lf - add;
  a->rg = b->rg + c->rg - add;
  return a;
}
int n, m;
char s[N];
Node* root = new Node();
void build(Node* v = root, int l = 0, int r = n) {
  if (r - l == 1) {
    *v = Node(s[l]);
  } else {
    int m = (l + r) / 2;
    v->l = new Node();
    build(v->l, l, m);
    v->r = new Node();
    build(v->r, m, r);
    comb(v->l, v->r, v);
  }
}
Node* get(int L, int R, Node* v = root, int l = 0, int r = n) {
  if (L <= l && r <= R) {
    return v;
  }
  if (R <= l || r <= L) {
    return new Node();
  }
  int m = (l + r) / 2;
  return comb(get(L, R, v->l, l, m), get(L, R, v->r, m, r));
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  build();
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", 2 * get(l - 1, r)->res);
  }
  return 0;
}
