#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
using namespace std;
inline long long in() {
  long long x;
  scanf("%lld", &x);
  return x;
}
struct node {
  long long len = 0, cl = 0, op = 0;
};
long long n;
node combine(node l, node r) {
  node res;
  long long x = min(l.op, r.cl);
  res.len = (l.len + r.len) + 2 * x;
  res.op = l.op + r.op - x;
  res.cl = l.cl + r.cl - x;
  return res;
}
vector<node> t;
void build() {
  for (long long i = n - 1; i > 0; i--) {
    t[i] = combine(t[i << 1], t[i << 1 | 1]);
  }
}
long long qu(long long l, long long r) {
  node rl, rr;
  for (l += n, r += n; l < r; l /= 2, r /= 2) {
    if (l & 1) rl = combine(rl, t[l++]);
    if (r & 1) rr = combine(t[--r], rr);
  }
  return combine(rl, rr).len;
}
int32_t main() {
  string s;
  cin >> s;
  n = s.length();
  t = vector<node>(2 * n);
  for (long long i = 0; i < n; i++) {
    if (s[i] == ')')
      t[n + i].cl = 1;
    else
      t[n + i].op = 1;
  }
  build();
  long long q = in();
  long long l, r;
  while (q--) {
    l = in();
    r = in();
    l--;
    cout << qu(l, r) << "\n";
  }
}
