#include <bits/stdc++.h>
using namespace std;
string p;
struct R {
  long long int open, close, len;
  R() { open = close = len = 0; }
};
R seg[4 * 1000005];
void combine(R a, R b, R &c) {
  long long int f = min(a.open, b.close);
  c.open = a.open + b.open - f;
  c.close = a.close + b.close - f;
  c.len = a.len + b.len + 2 * f;
}
void build(long long int node, long long int s, long long int e) {
  if (s == e) {
    if (p[s] == '(')
      seg[node].open++;
    else
      seg[node].close++;
    return;
  }
  build(2 * node, s, (s + e) / 2);
  build(2 * node + 1, (s + e) / 2 + 1, e);
  combine(seg[2 * node], seg[2 * node + 1], seg[node]);
}
R query(long long int node, long long int s, long long int e, long long int x,
        long long int y) {
  if (s > e or s > y or e < x) {
    R y;
    return y;
  }
  if (s >= x and e <= y) return seg[node];
  long long int mid = (s + e) / 2;
  R p1 = query(2 * node, s, mid, x, y);
  R p2 = query(2 * node + 1, mid + 1, e, x, y);
  R w;
  combine(p1, p2, w);
  return w;
}
int main() {
  long long int i, j, k, q, x, y;
  cin >> p;
  cin >> q;
  build(1, 0, (long long int)p.size() - 1);
  while (q--) {
    cin >> x >> y;
    x--, y--;
    cout << query(1, 0, (long long int)p.size() - 1, x, y).len << '\n';
  }
}
