#include <bits/stdc++.h>
using namespace std;
const int N = 1e6, mod = 7 + 1e9;
const double eps = 1e-9;
inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
inline int mul(int a, int b) { return (long long)a * b % mod; }
int num[4 * N], lft[4 * N], rght[4 * N];
string s;
void build(int p, int l, int r) {
  if (l == r) {
    num[p] = 0;
    lft[p] = (s[l] == ')');
    rght[p] = (s[l] == '(');
    return;
  }
  int md = l + (r - l) / 2;
  build(p * 2, l, md);
  build(p * 2 + 1, md + 1, r);
  num[p] = num[p * 2] + num[p * 2 + 1] + min(rght[p * 2], lft[p * 2 + 1]);
  rght[p] = rght[p * 2] + rght[p * 2 + 1] - min(rght[p * 2], lft[p * 2 + 1]);
  lft[p] = lft[p * 2] + lft[p * 2 + 1] - min(rght[p * 2], lft[p * 2 + 1]);
}
struct st {
  int n, l, r;
};
st get(int p, int l, int r, int a, int b) {
  if (a <= l && r <= b) {
    return {num[p], lft[p], rght[p]};
  }
  if (l > b || r < a) return {0, 0, 0};
  int md = l + (r - l) / 2;
  st x = get(p * 2, l, md, a, b), y = get(p * 2 + 1, md + 1, r, a, b);
  return {x.n + y.n + min(x.r, y.l), x.l + y.l - min(x.r, y.l),
          x.r + y.r - min(x.r, y.l)};
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s;
  int n = s.size();
  build(1, 0, n - 1);
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << get(1, 0, n - 1, l - 1, r - 1).n * 2 << '\n';
  }
}
