#include <bits/stdc++.h>
using namespace std;
int _I() {
  int x;
  scanf("%d", &x);
  return x;
}
long long _IL() {
  long long x;
  scanf("%lld", &x);
  return x;
}
const int MX = 1e6;
struct Node {
  int ans, op, cl;
  Node(){};
  Node(int x, int y, int z) {
    ans = x;
    op = y;
    cl = z;
  }
};
Node node[(4 * MX) + 7];
string s;
void build(int id, int l, int r) {
  if (l == r) {
    node[id] = Node(0, s[l] == '(', s[l] == ')');
    return;
  }
  int mid = (l + r) / 2;
  int lft = 2 * id;
  int rgt = lft + 1;
  build(lft, l, mid);
  build(rgt, mid + 1, r);
  int total = min(node[lft].op, node[rgt].cl);
  int ans = node[lft].ans + node[rgt].ans + total;
  int op = node[lft].op + node[rgt].op - total;
  int cl = node[lft].cl + node[rgt].cl - total;
  node[id] = Node(ans, op, cl);
}
Node query(int id, int l, int r, int st, int ed) {
  if (l > ed || r < st)
    return Node(0, 0, 0);
  else if (l >= st && r <= ed) {
    return node[id];
  }
  int mid = (l + r) / 2;
  int lft = 2 * id;
  int rgt = lft + 1;
  Node p = query(lft, l, mid, st, ed);
  Node q = query(rgt, mid + 1, r, st, ed);
  int total = min(p.op, q.cl);
  int ans = p.ans + q.ans + total;
  int op = p.op + q.op - total;
  int cl = p.cl + q.cl - total;
  return Node(ans, op, cl);
}
void solve() {
  cin >> s;
  int l = s.size();
  build(1, 0, l - 1);
  int q = _I();
  while (q--) {
    int x = _I();
    int y = _I();
    printf("%d\n", query(1, 0, l - 1, x - 1, y - 1).ans * 2);
  }
}
int main() {
  solve();
  return 0;
}
