#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
const int maxm = 100010;
struct node {
  int l, r, id;
} qu[maxm];
int tree[maxn];
int n, ans[maxn], m;
string a;
bool cmp(node a, node b) { return a.l > b.l; }
void update(int x) {
  while (x < m) {
    tree[x] += 1;
    x += (x & (-x));
  }
}
int sum(int i) {
  int ans = 0;
  while (i > 0) {
    ans += tree[i];
    i -= (i & (-i));
  }
  return ans;
}
void solve() {
  int j = 0;
  m = a.size();
  stack<int> s;
  memset(tree, 0, sizeof(tree));
  for (int i = m - 1; i >= 0; i--) {
    if (a[i] == ')')
      s.push(i);
    else if (!s.empty()) {
      update(s.top());
      s.pop();
    }
    while (j < n && qu[j].l == i) {
      ans[qu[j].id] = sum(qu[j].r);
      j++;
    }
  }
  for (int i = 0; i < n; i++) cout << ans[i] * 2 << endl;
}
int main() {
  cin >> a >> n;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    qu[i].l = l - 1;
    qu[i].r = r - 1;
    qu[i].id = i;
  }
  sort(qu, qu + n, cmp);
  solve();
  return 0;
}
