#include <bits/stdc++.h>
using namespace std;
const int N = 1000006;
struct node {
  int first, second, len;
  node() { first = second = len = 0; }
};
node tree[4 * N + 5];
node dum;
string expr;
node merge_n(node a, node b) {
  node res;
  int redo = min(a.first, b.second);
  res.first = a.first + b.first - redo;
  res.second = a.second + b.second - redo;
  res.len = a.len + b.len + 2 * redo;
  return res;
}
void build(int l, int r, int trind) {
  if (l == r) {
    if (expr[l] == '(') {
      tree[trind].first = 1;
      tree[trind].second = 0;
    } else {
      tree[trind].second = 1;
      tree[trind].first = 0;
    }
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, 2 * trind + 1);
  build(mid + 1, r, 2 * trind + 2);
  tree[trind] = merge_n(tree[2 * trind + 1], tree[2 * trind + 2]);
}
node query(int l, int r, int ql, int qr, int trind) {
  if (l > qr || r < ql) return dum;
  if (l >= ql && r <= qr) return tree[trind];
  int mid = (l + r) / 2;
  return merge_n(query(l, mid, ql, qr, 2 * trind + 1),
                 query(mid + 1, r, ql, qr, 2 * trind + 2));
}
int main(int argc, char const *argv[]) {
  cin >> expr;
  int n = expr.length();
  build(0, n - 1, 0);
  int m;
  scanf("%d", &m);
  while (m--) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", query(0, n - 1, l - 1, r - 1, 0).len);
  }
  return 0;
}
