#include <bits/stdc++.h>
using namespace std;
struct BIT {
  int n;
  vector<int> a;
  BIT(int _n) {
    n = _n;
    a = vector<int>(n + 1, 0);
  }
  int sum(int k) {
    int ans = 0;
    for (int idx = k; idx > 0; idx -= (idx & -idx)) ans += a[idx];
    return ans;
  }
  int query(int l, int r) { return sum(r) - sum(l - 1); }
  void update(int k, int v) {
    for (int idx = k; idx <= n; idx += (idx & -idx)) a[idx] += v;
  }
};
struct intv {
  int l, r, id;
  intv() {}
  intv(int _l, int _r) : l(_l), r(_r) {}
  bool operator<(const intv& rhs) const { return r < rhs.r; }
};
const int N = 1000000 + 10;
char s[N];
stack<int> lb;
vector<intv> p, q;
vector<int> ans;
int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    if (s[i] == '(') {
      lb.push(i);
    } else if (lb.size()) {
      p.push_back(intv(lb.top(), i));
      lb.pop();
    }
  }
  int m;
  scanf("%d", &m);
  q = vector<intv>(m);
  ans = vector<int>(m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &q[i].l, &q[i].r);
    q[i].id = i;
  }
  sort(q.begin(), q.end());
  BIT bit(n);
  int qTop = 0, pTop = 0;
  for (int i = 1; i <= n; i++) {
    for (; pTop < p.size() && p[pTop].r == i; pTop++) {
      const intv& top = p[pTop];
      bit.update(top.l, 1);
    }
    for (; qTop < m && q[qTop].r == i; qTop++) {
      const intv& top = q[qTop];
      ans[top.id] = bit.query(top.l, top.r) * 2;
    }
  }
  for (int i = 0; i < m; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
