#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
struct node {
  int l, r;
  int a, b, sum;
  node operator+(const node m) {
    node ans;
    int minn = min(a, m.b);
    ans.sum = sum + m.sum + minn * 2;
    ans.a = a + m.a - minn;
    ans.b = b + m.b - minn;
    return ans;
  }
} tree[4 * N];
string s;
void push_up(int x) {
  int minn = min(tree[x << 1].a, tree[x << 1 | 1].b);
  tree[x].sum = tree[x << 1].sum + tree[x << 1 | 1].sum + minn * 2;
  tree[x].a = tree[x << 1].a + tree[x << 1 | 1].a - minn;
  tree[x].b = tree[x << 1].b + tree[x << 1 | 1].b - minn;
}
void build(int x, int l, int r) {
  tree[x].l = l;
  tree[x].r = r;
  tree[x].a = tree[x].b = tree[x].sum = 0;
  if (l == r) {
    if (s[l - 1] == '(')
      tree[x].a = 1;
    else
      tree[x].b = 1;
    tree[x].sum = 0;
    return;
  }
  int m = (l + r) / 2;
  build(x << 1, l, m);
  build(x << 1 | 1, m + 1, r);
  push_up(x);
}
node query(int x, int l, int r) {
  int L = tree[x].l, R = tree[x].r;
  if (l <= L && R <= r) {
    return tree[x];
  }
  int m = (L + R) / 2;
  if (r <= m)
    return query(x << 1, l, r);
  else if (l > m)
    return query(x << 1 | 1, l, r);
  else
    return query(x << 1, l, r) + query(x << 1 | 1, l, r);
}
int main() {
  cin >> s;
  build(1, 1, (int)s.length());
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << query(1, l, r).sum << endl;
  }
  return 0;
}
