#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long binExp(long long x, long long n) {
  long long r = 1;
  while (n > 0) {
    if (n % 2 == 1) r = r * x;
    x = x * x;
    n = n / 2;
  }
  return r;
}
long long modbinExp(long long x, long long n, long long M) {
  long long r = 1;
  while (n > 0) {
    if (n % 2 == 1) r = (r * x) % M;
    x = (x * x) % M;
    n = n / 2;
  }
  return r;
}
struct data1 {
  long long op, cl, mat;
};
data1 tree[4 * 1000005], nul;
string str;
data1 combine(data1 a, data1 b) {
  data1 c = nul;
  long long x = min(a.op, b.cl);
  c.mat = a.mat + b.mat + x;
  c.op = a.op + b.op - x;
  c.cl = a.cl + b.cl - x;
  return c;
}
void build(long long node = 1, long long s = 0, long long e = str.size() - 1) {
  if (s == e) {
    tree[node] = nul;
    if (str[s] == '(')
      tree[node].op = 1;
    else
      tree[node].cl = 1;
  } else {
    long long mid = (s + e) / 2;
    build(2 * node, s, mid);
    build(2 * node + 1, mid + 1, e);
    tree[node] = combine(tree[2 * node], tree[2 * node + 1]);
  }
}
data1 query(long long l, long long r, long long node = 1, long long s = 0,
            long long e = str.size() - 1) {
  if (s > e || s > r || e < l) return nul;
  if (s >= l && e <= r) return tree[node];
  long long mid = (s + e) / 2;
  data1 p1 = query(l, r, 2 * node, s, mid);
  data1 p2 = query(l, r, 2 * node + 1, mid + 1, e);
  return combine(p1, p2);
}
void solve() {
  cin >> str;
  nul.op = 0;
  nul.cl = 0;
  nul.mat = 0;
  long long m, x, y;
  cin >> m;
  build();
  while (m--) {
    cin >> x >> y;
    cout << 2 * query(x - 1, y - 1).mat << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
}
