#include <bits/stdc++.h>
using namespace std;
const int OO = 1e6 + 10;
const long long MOD = 1e9 + 7;
const int MAX = 2e5 + 50;
const double EPS = (1e-9);
string str;
struct node {
  int l = 0, r = 0, correct = 0;
  node() {}
  node(int a, int b, int c) { l = a, r = b, correct = c; }
};
node seg[4123456];
node merge(node L, node R) {
  node ret;
  int temp = min(L.l, R.r);
  ret.l = L.l - temp + R.l;
  ret.r = R.r - temp + L.r;
  ret.correct = L.correct + R.correct + temp;
  return ret;
}
node build(int idx = 1, int l = 0, int r = (int)str.size() - 1) {
  if (l == r) return seg[idx] = node(str[l] == '(', str[r] == ')', 0);
  int mid = (l + r) / 2;
  node L, R, ret;
  L = build(idx * 2, l, mid);
  R = build(idx * 2 + 1, mid + 1, r);
  ret = merge(L, R);
  return seg[idx] = ret;
}
node qu(int st, int en, int idx = 1, int l = 0, int r = (int)str.size() - 1) {
  if (l > en || r < st) return node(0, 0, 0);
  if (l >= st && r <= en) return seg[idx];
  int mid = (l + r) / 2;
  node L, R, ret;
  L = qu(st, en, idx * 2, l, mid);
  R = qu(st, en, idx * 2 + 1, mid + 1, r);
  ret = merge(L, R);
  return ret;
}
int main() {
  cin >> str;
  build();
  int q;
  cin >> q;
  while (q--) {
    int st, en;
    cin >> st >> en;
    st--, en--;
    cout << qu(st, en).correct * 2 << "\n";
  }
  return 0;
}
