#include <bits/stdc++.h>
using namespace std;
char str[1000005];
struct Tree {
  int open, close, len;
};
Tree tree[4 * 1000005];
Tree Merge(Tree ob1, Tree ob2) {
  Tree ob;
  int mn = min(ob1.open, ob2.close);
  ob.len = ob1.len + ob2.len + (mn * 2);
  ob.open = ob1.open + ob2.open - mn;
  ob.close = ob1.close + ob2.close - mn;
  return ob;
}
Tree make_data(int op, int cl, int l) {
  Tree ob;
  ob.open = op;
  ob.close = cl;
  ob.len = l;
  return ob;
}
void build(int node, int b, int e) {
  if (b == e) {
    tree[node].open = (str[b - 1] == '(');
    tree[node].close = (str[b - 1] == ')');
    tree[node].len = 0;
    return;
  }
  int mid = (b + e) >> 1;
  int Left = node << 1;
  int Right = Left + 1;
  build(Left, b, mid);
  build(Right, mid + 1, e);
  tree[node] = Merge(tree[Left], tree[Right]);
}
Tree query(int node, int b, int e, int i, int j) {
  if (i > e || j < b) return make_data(0, 0, 0);
  if (b >= i && e <= j) return tree[node];
  int mid = (b + e) >> 1;
  int Left = node << 1;
  int Right = Left + 1;
  Tree p1 = query(Left, b, mid, i, j);
  Tree p2 = query(Right, mid + 1, e, i, j);
  return Merge(p1, p2);
}
int main() {
  int n, i, j, l, r;
  scanf("%s %d", str, &n);
  int x = strlen(str);
  build(1, 1, x);
  while (n--) {
    scanf("%d %d", &l, &r);
    Tree ans = query(1, 1, x, l, r);
    printf("%d\n", ans.len);
  }
  return 0;
}
