#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("omit-frame-pointer")
#pragma GCC optimize("unroll-loops")
const int MAXINT = 2147483640;
const long long MAXLL = 9223372036854775800LL;
const long long MAXN = 1000000;
const double pi = 3.1415926535897932384626433832795;
using namespace std;
struct di4 {
  long long l, r, ans;
};
di4 t[4000000];
di4 combine(di4 t1, di4 t2) {
  long long kol = min(t1.l, t2.r);
  di4 data;
  data.ans = t1.ans + t2.ans + kol * 2;
  data.l = t1.l + t2.l - kol;
  data.r = t1.r + t2.r - kol;
  return data;
}
void modify(long long v, long long tl, long long tr, long long pos,
            long long val1, long long val2) {
  if (tl == tr) {
    t[v].l += val1;
    t[v].r += val2;
    return;
  } else {
    long long tm = (tl + tr) / 2;
    if (pos <= tm)
      modify(v * 2, tl, tm, pos, val1, val2);
    else
      modify(v * 2 + 1, tm + 1, tr, pos, val1, val2);
    t[v] = combine(t[v * 2], t[v * 2 + 1]);
  }
}
di4 get(long long v, long long tl, long long tr, long long l, long long r) {
  if (tl == l and tr == r) return t[v];
  long long tm = (tl + tr) / 2;
  if (r <= tm) return get(v * 2, tl, tm, l, min(r, tm));
  if (l > tm) return get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
  return combine(get(v * 2, tl, tm, l, min(r, tm)),
                 get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  srand(time(0));
  long long n, i, q, a, b, n1;
  char k;
  string s;
  cin >> s;
  n1 = s.size();
  for (i = 0; i < s.size(); i++) {
    if (s[i] == '(')
      modify(1, 1, n1, i + 1, 1, 0);
    else
      modify(1, 1, n1, i + 1, 0, 1);
  }
  cin >> q;
  for (i = 1; i <= q; i++) {
    cin >> a >> b;
    cout << get(1, 1, n1, a, b).ans << "\n";
  }
  return 0;
}
