#include <bits/stdc++.h>
using namespace std;
using namespace std;
struct node {
  int o, c, s;
};
node t[5000000];
node combine(node a, node b) {
  node ans;
  ans.s = a.s + b.s;
  int z = min(a.o, b.c);
  ans.o = a.o + b.o - z;
  ans.c = a.c + b.c - z;
  ans.s = ans.s + z + z;
  return ans;
}
void build(string &v, int i, int tl, int tr) {
  if (tl == tr) {
    node tt;
    if (v[tl] == ')') {
      tt.o = 0;
      tt.c = 1;
      tt.s = 0;
    } else {
      tt.o = 1;
      tt.c = 0;
      tt.s = 0;
    }
    t[i] = tt;
  } else {
    int tm = (tl + tr) / 2;
    build(v, 2 * i, tl, tm);
    build(v, 2 * i + 1, tm + 1, tr);
    t[i] = combine(t[2 * i], t[2 * i + 1]);
  }
}
node query(int i, int tl, int tr, int l, int r) {
  if (l > r) {
    node tt;
    tt.o = 0;
    tt.c = 0;
    tt.s = 0;
    return tt;
  }
  if (tl == l && tr == r) {
    return t[i];
  }
  int tm = (tl + tr) / 2;
  return combine(query(2 * i, tl, tm, l, min(tm, r)),
                 query(2 * i + 1, tm + 1, tr, max(l, tm + 1), r));
}
int main() {
  string s;
  cin >> s;
  int n = s.size();
  build(s, 1, 0, n - 1);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    cout << query(1, 0, n - 1, a, b).s << endl;
  }
}
