#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 123;
const int mod = 1e9 + 7;
const int INF = 2e9 + 1;
const long long INFL = 3e18 + 1;
const double pi = acos(-1.0);
char s[N];
string a;
int m, n;
struct node {
  int open, close, val;
  node() { open = close = val = 0; }
} t[4 * N], none;
void build(int v = 1, int tl = 1, int tr = n) {
  if (tl == tr) {
    if (s[tl] == '(')
      t[v].open++;
    else
      t[v].close++;
    return;
  }
  int tm = (tl + tr) / 2;
  build(v + v, tl, tm);
  build(v + v + 1, tm + 1, tr);
  int com = min(t[v + v].open, t[v + v + 1].close);
  t[v].open = t[v + v].open + t[v + v + 1].open - com;
  t[v].close = t[v + v].close + t[v + v + 1].close - com;
  t[v].val = t[v + v].val + t[v + v + 1].val + com;
}
node get(int l, int r, int v = 1, int tl = 1, int tr = n) {
  if (tl > r || tr < l) return none;
  if (l <= tl && tr <= r) return t[v];
  int tm = (tl + tr) / 2;
  node a = get(l, r, v + v, tl, tm);
  node b = get(l, r, v + v + 1, tm + 1, tr);
  node ans;
  int com = min(a.open, b.close);
  ans.open = a.open + b.open - com;
  ans.close = a.close + b.close - com;
  ans.val = a.val + b.val + com;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> m;
  n = (int)a.size();
  for (int i = 1; i <= n; i++) s[i] = a[i - 1];
  build();
  while (m--) {
    int l, r;
    cin >> l >> r;
    node x = get(l, r);
    cout << x.val + x.val << endl;
  }
  return 0;
}
