#include <bits/stdc++.h>
using namespace std;
struct Node {
  int optimal;
  int open;
  int close;
  Node() { optimal = open = close = 0; }
  Node(int a, int b, int c) {
    optimal = a;
    open = b;
    close = c;
  }
};
Node operator+(const Node& left, const Node& right) {
  Node res;
  int tmp = min(left.open, right.close);
  res.optimal = left.optimal + right.optimal + tmp;
  res.open = left.open + right.open - tmp;
  res.close = left.close + right.close - tmp;
  return res;
}
int n, m, l, r;
string s;
Node st[1000001 << 2];
void build(int root, int l, int r) {
  if (l > r) return;
  if (l == r) {
    if (s[l - 1] == '(')
      st[root] = Node(0, 1, 0);
    else
      st[root] = Node(0, 0, 1);
    return;
  }
  int mid = (l + r) >> 1;
  build(root << 1, l, mid);
  build(root << 1 ^ 1, mid + 1, r);
  st[root] = st[root << 1] + st[root << 1 ^ 1];
}
Node get(int root, int l, int r, int u, int v) {
  if (v < l || u > r) return Node(0, 0, 0);
  if (l >= u && r <= v) return st[root];
  int mid = (l + r) >> 1;
  return (get(root << 1, l, mid, u, v) + get(root << 1 ^ 1, mid + 1, r, u, v));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s;
  n = ((int)(s).size());
  build(1, 1, n);
  cin >> m;
  while (m--) {
    cin >> l >> r;
    cout << get(1, 1, n, l, r).optimal * 2 << endl;
  }
}
