#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
struct vertex {
  int ans, l, r;
  vertex() { ans = l = r = 0; }
  vertex(char c) {
    ans = l = r = 0;
    if (c == '(') l = 1;
    if (c == ')') r = 1;
  }
};
vertex t[4 * N];
string s;
vertex merge(vertex v, vertex u) {
  vertex res;
  int add = min(u.r, v.l);
  res.ans = v.ans + u.ans + add;
  res.l = v.l + u.l - add;
  res.r = v.r + u.r - add;
  return res;
}
void build(int v, int tl, int tr) {
  if (tl == tr)
    t[v] = vertex(s[tl]);
  else {
    int tm = (tl + tr) / 2;
    build(v * 2 + 1, tl, tm);
    build(v * 2 + 2, tm + 1, tr);
    t[v] = merge(t[v * 2 + 1], t[v * 2 + 2]);
  }
}
vertex query(int v, int tl, int tr, int l, int r) {
  if (l > r) return vertex();
  if (tl == l && tr == r) return t[v];
  int tm = (tl + tr) / 2;
  vertex res = merge(query(v * 2 + 1, tl, tm, l, min(tm, r)),
                     query(v * 2 + 2, tm + 1, tr, max(tm + 1, l), r));
  return res;
}
int main() {
  int n, m;
  cin >> s >> m;
  n = s.size();
  build(0, 0, n - 1);
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    vertex q = query(0, 0, n - 1, l - 1, r - 1);
    cout << q.ans * 2 << endl;
  }
  return 0;
}
