#include <bits/stdc++.h>
using namespace std;
int n;
char a[1000005];
int q;
struct node {
  int optimal;
  int open;
  int close;
  node(int op = 0, int cl = 0, int o = 0) {
    optimal = op;
    open = o;
    close = cl;
  }
};
node t[4 * 1000005];
node operator+(const node &left, const node &right) {
  node res;
  int t = min(left.open, right.close);
  res.optimal = left.optimal + right.optimal + t;
  res.close = left.close + right.close - t;
  res.open = left.open + right.open - t;
  return res;
}
void update(int k, int l, int r) {
  if (l == r) {
    if (a[l] == '(')
      t[k] = node(0, 1, 0);
    else
      t[k] = node(0, 0, 1);
    return;
  }
  int m = (l + r) / 2;
  update(k * 2, l, m);
  update(k * 2 + 1, m + 1, r);
  t[k] = t[k * 2 + 1] + t[k * 2];
}
node query(int k, int l, int r, int u, int v) {
  if (v < l || u > r) return node(0, 0, 0);
  if (u <= l && v >= r) {
    return t[k];
  }
  int m = (l + r) / 2;
  return (query(k * 2 + 1, m + 1, r, u, v) + query(k * 2, l, m, u, v));
}
int main() {
  scanf("%s", a + 1);
  n = strlen(a + 1);
  update(1, 1, n);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    printf("%d\n", query(1, 1, n, u, v).optimal * 2);
  }
}
