#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
const int OO = 1e9;
string x;
int n;
struct node {
  int opened = 0;
  int closed = 0;
  int ans = 0;
};
node sg[4 * N];
node mergge(node left, node right) {
  node c;
  int xx = min(left.opened, right.closed);
  c.ans = xx + left.ans + right.ans;
  c.opened = right.opened + left.opened - xx;
  c.closed = left.closed + right.closed - xx;
  return c;
}
node build(int idx, int l, int r) {
  if (l > r) {
    node a;
    return a;
  }
  if (l == r) {
    node a;
    if (x[l] == '(') {
      a.opened++;
    } else
      a.closed++;
    return sg[idx] = a;
  }
  int m = (l + r) / 2;
  node prt1 = build(2 * idx + 1, l, m);
  node prt2 = build(2 * idx + 2, m + 1, r);
  return sg[idx] = mergge(prt1, prt2);
}
node query(int idx, int l, int r, int st, int ed) {
  if (ed < l || st > r) {
    node a;
    return a;
  }
  if (l >= st && r <= ed) return sg[idx];
  int m = (l + r) / 2;
  node prt1 = query(2 * idx + 1, l, m, st, ed);
  node prt2 = query(2 * idx + 2, m + 1, r, st, ed);
  return mergge(prt1, prt2);
}
int main() {
  cin >> x;
  build(0, 0, x.size() - 1);
  int q;
  scanf("%d", &q);
  while (q--) {
    int aa, ab;
    scanf("%d %d", &aa, &ab);
    printf("%d\n", query(0, 0, x.size() - 1, aa - 1, ab - 1).ans * 2);
  }
  return 0;
}
