#include <bits/stdc++.h>
using namespace ::std;
string s;
pair<int, pair<int, int>> st[4000005];
pair<int, pair<int, int>> build(int i, int l, int r) {
  if (l + 1 == r) return st[i] = {0, {s[l] == '(', s[l] == ')'}};
  int mid = l + (r - l) / 2;
  auto t1 = build(i * 2, l, mid), t2 = build(i * 2 + 1, mid, r);
  st[i] = {t1.first + t2.first + min(t1.second.first, t2.second.second),
           {t1.second.first + t2.second.first -
                min(t1.second.first, t2.second.second),
            t1.second.second + t2.second.second -
                min(t1.second.first, t2.second.second)}};
  return st[i];
}
pair<int, pair<int, int>> query(int i, int l, int r, int s, int e) {
  if (s <= l && r <= e) return st[i];
  if (e <= l || s >= r) return {0, {0, 0}};
  int mid = l + (r - l) / 2;
  auto t1 = query(i * 2, l, mid, s, e), t2 = query(i * 2 + 1, mid, r, s, e);
  return {t1.first + t2.first + min(t1.second.first, t2.second.second),
          {t1.second.first + t2.second.first -
               min(t1.second.first, t2.second.second),
           t1.second.second + t2.second.second -
               min(t1.second.first, t2.second.second)}};
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> s;
  int n = s.length(), m;
  cin >> m;
  build(1, 0, n);
  int l, r;
  while (m--) {
    cin >> l >> r;
    l--, r--;
    cout << query(1, 0, n, l, r + 1).first * 2 << '\n';
  }
}
