#include <bits/stdc++.h>
using namespace std;
string a;
struct info {
  int open, close, match;
  info() {}
  info(int a, int b, int c) { open = a, close = b, match = c; }
  info operator+(info &right) {
    int temp = min(open, right.close);
    return info(open + right.open - temp, close + right.close - temp,
                match + right.match + temp);
  }
};
info tree[3 * 1000001];
void init(int n, int b, int e) {
  if (b == e) {
    tree[n] = (a[b - 1] == '(') ? info(1, 0, 0) : info(0, 1, 0);
    return;
  }
  int m = (b + e) / 2;
  int left = 2 * n, right = left + 1;
  init(left, b, m);
  init(right, m + 1, e);
  tree[n] = tree[left] + tree[right];
}
info query(int n, int b, int e, int l, int r) {
  if (e < l || b > r) return info(0, 0, 0);
  if (b >= l && e <= r) return tree[n];
  int m = (b + e) / 2;
  int left = 2 * n, right = left + 1;
  info p1 = query(left, b, m, l, r);
  info p2 = query(right, m + 1, e, l, r);
  info temp = p1 + p2;
  return temp;
}
int main() {
  cin >> a;
  init(1, 1, a.size());
  int q;
  cin >> q;
  int l, r;
  while (q--) {
    cin >> l >> r;
    cout << 2 * (query(1, 1, a.size(), l, r)).match << endl;
  }
  return 0;
}
