#include <bits/stdc++.h>
using namespace std;
const int Nci = 1e6 + 4;
const int Inf = 1e6 + 4;
const int Mod = 1e9 + 7;
string s;
struct node {
  int cs, o, c;
} st[4 * Nci];
node Trade(node a, node b) {
  node res;
  int minn = min(a.o, b.c);
  res.cs = a.cs + b.cs + minn;
  res.o = a.o + b.o - minn;
  res.c = a.c + b.c - minn;
  return res;
}
void build(int id, int l, int r) {
  if (l == r) {
    if (s[l] == '(') {
      st[id].cs = st[id].c = 0;
      st[id].o = 1;
    } else {
      st[id].cs = st[id].o = 0;
      st[id].c = 1;
    }
    return;
  }
  int mid = (l + r) >> 1;
  build(id * 2, l, mid);
  build(id * 2 + 1, mid + 1, r);
  st[id] = Trade(st[id * 2], st[id * 2 + 1]);
}
node get(int id, int l, int r, int u, int v) {
  if (l == u && v == r) return st[id];
  int mid = (l + r) >> 1;
  if (v <= mid) return get(id * 2, l, mid, u, v);
  if (u > mid) return get(id * 2 + 1, mid + 1, r, u, v);
  return Trade(get(id * 2, l, mid, u, mid),
               get(id * 2 + 1, mid + 1, r, mid + 1, v));
}
void Solve() {
  cin >> s;
  int t;
  cin >> t;
  int n = s.size();
  build(1, 0, n - 1);
  for (int i = 0; i < t; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    node ans = get(1, 0, n - 1, x, y);
    cout << ans.cs * 2 << "\n";
  }
}
int32_t main() {
  if (ifstream(""
               ".inp")) {
    freopen(
        ""
        ".inp",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  }
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int ntest = 1;
  while (ntest--) {
    Solve();
  }
  return 0;
}
