#include <bits/stdc++.h>
using namespace std;
struct Node {
  int a, b, c;
  Node() { a = 0, b = 0, c = 0; }
  Node(int x) {
    a = 0;
    if (x == -1) {
      c = 1;
      b = 0;
    } else {
      b = 1, c = 0;
    }
  }
};
Node sum(Node a, Node b) {
  if (a.a == 0 && a.b == 0 && a.c == 0) return b;
  if (b.a == 0 && b.b == 0 && b.c == 0) return a;
  Node ans;
  int t = min(a.b, b.c);
  ans.a = a.a + b.a + t;
  ans.b = a.b + b.b - t;
  ans.c = a.c + b.c - t;
  return ans;
}
string a;
vector<Node> t;
void build(int v, int l, int r) {
  if (l == r) {
    if (a[l] == '(')
      t[v] = Node(1);
    else
      t[v] = Node(-1);
  } else {
    int m = (l + r) / 2;
    build(2 * v, l, m);
    build(2 * v + 1, m + 1, r);
    t[v] = sum(t[2 * v], t[2 * v + 1]);
  }
}
Node get(int v, int tl, int tr, int l, int r) {
  if (tl > tr || l > r) return Node();
  if (tl == l && tr == r)
    return t[v];
  else {
    int tm = (tl + tr) / 2;
    Node x1 = get(2 * v, tl, tm, l, min(r, tm));
    Node x2 = get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
    return sum(x1, x2);
  }
}
int main() {
  cin >> a;
  int n = a.size();
  t.resize(4 * a.size());
  build(1, 0, n - 1);
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    --l, --r;
    Node x1 = get(1, 0, n - 1, l, r);
    cout << 2 * x1.a << endl;
  }
}
