#include <bits/stdc++.h>
using namespace std;
const int size = 1000007;
const long long modulo = 1000000007;
const long long INF = 1e18;
const double EPS = 1e-6;
struct ParenthSequence {
  int opened, closed, complete;
  ParenthSequence(int o = 0, int c = 0, int co = 0)
      : opened(o), closed(c), complete(co) {}
};
ParenthSequence merge_them(ParenthSequence& a, ParenthSequence& b) {
  ParenthSequence res;
  res.opened = b.opened + max(0, a.opened - b.closed);
  res.closed = a.closed + max(0, b.closed - a.opened);
  res.complete = a.complete + b.complete + min(a.opened, b.closed);
  return res;
}
ParenthSequence t[size * 4];
string s;
void build(int v, int tl, int tr) {
  if (tl == tr) {
    if (s[tl] == '(')
      t[v] = ParenthSequence(1, 0, 0);
    else
      t[v] = ParenthSequence(0, 1, 0);
  } else {
    int mid = (tl + tr) / 2;
    build(2 * v, tl, mid);
    build(2 * v + 1, mid + 1, tr);
    t[v] = merge_them(t[2 * v], t[2 * v + 1]);
  }
}
ParenthSequence sum(int v, int tl, int tr, int l, int r) {
  if (l > r) return ParenthSequence();
  if (tl == l && tr == r)
    return t[v];
  else {
    int mid = (tl + tr) / 2;
    ParenthSequence a = sum(2 * v, tl, mid, l, min(mid, r));
    ParenthSequence b = sum(2 * v + 1, mid + 1, tr, max(mid + 1, l), r);
    return merge_them(a, b);
  }
}
int main() {
  cin >> s;
  int n = s.size();
  build(1, 0, n - 1);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    --l;
    --r;
    cout << sum(1, 0, n - 1, l, r).complete * 2 << endl;
  }
  return 0;
}
