#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000 + 10;
string s;
int N;
struct node {
  int optimal;
  int open;
  int close;
};
vector<node> st;
node operator+(const node& left, const node& right) {
  node res = {0, 0, 0};
  int tmp = min(left.open, right.close);
  res.optimal = left.optimal + right.optimal + tmp;
  res.open = left.open + right.open - tmp;
  res.close = left.close + right.close - tmp;
  return res;
}
void build(int l, int r, int id) {
  if (l == r) {
    if (s[l] == '(')
      st[id] = {0, 1, 0};
    else
      st[id] = {0, 0, 1};
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, id * 2);
  build(mid + 1, r, id * 2 + 1);
  st[id] = st[id * 2] + st[id * 2 + 1];
}
node query(int id, int l, int r, int u, int v) {
  if (u > r || v < l) return {0, 0, 0};
  if (u <= l && v >= r) return st[id];
  int mid = (l + r) / 2;
  return query(id * 2, l, mid, u, v) + query(id * 2 + 1, mid + 1, r, u, v);
}
int main() {
  st.resize(MAXN * 4);
  int l, r;
  cin >> s;
  int k = s.length();
  s = '1' + s;
  build(1, k, 1);
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    scanf("%d %d", &l, &r);
    node tmp = query(1, 1, k, l, r);
    cout << tmp.optimal * 2 << endl;
  }
  return 0;
}
