#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int n, m;
char a[maxn];
struct data {
  int open, close, all;
  data() {
    open = 0;
    close = 0;
    all = 0;
  }
  data(int _open, int _close, int _all) {
    open = _open;
    close = _close;
    all = _all;
  }
  friend data merge(const data &a, const data &b) {
    data ret;
    int match = min(a.open, b.close);
    ret.open = a.open + b.open - match;
    ret.close = a.close + b.close - match;
    ret.all = a.all + b.all + match;
    return ret;
  }
} seg[maxn << 2];
void init(int k, int b, int e) {
  if (b == e) {
    if (a[b] == '(')
      seg[k].open = 1;
    else
      seg[k].close = 1;
    return;
  }
  int m = (b + e) >> 1;
  init(k + k, b, m);
  init(k + k + 1, m + 1, e);
  seg[k] = merge(seg[k + k], seg[k + k + 1]);
}
data find(int k, int b, int e, int x, int y) {
  if (b > y or e < x) return data();
  if (b >= x and e <= y) return seg[k];
  int m = (b + e) >> 1;
  data l = find(k + k, b, m, x, y);
  data r = find(k + k + 1, m + 1, e, x, y);
  return merge(l, r);
}
int main() {
  scanf("%s", a + 1);
  n = strlen(a + 1);
  scanf("%d", &m);
  init(1, 1, n);
  for (int i = 1, l, r; i <= m; i++) {
    scanf("%d%d", &l, &r);
    printf("%d\n", find(1, 1, n, l, r).all << 1);
  }
  return 0;
}
