#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 17;
const int MX = (int)1e6 + 17;
const int MOD = (int)1e9 + 7;
const long long oo = LLONG_MAX;
const int INF = INT_MAX;
const long double Pi = 3.14159265358979323846264338327950288419716939937510;
const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, 1, 0, -1};
inline long long IN() {
  long long x = 0, ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void OUT(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    OUT(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
void IOI2017() {}
stack<int> st;
int n, q, l, r, ans;
int dp[MX];
char s[MX];
vector<int> t[MX * 4];
inline void build(int v = 1, int tl = 1, int tr = n) {
  if (tl == tr)
    t[v].push_back(dp[tl]);
  else {
    int tm = tl + tr >> 1;
    build(v << 1, tl, tm);
    build((v << 1) + 1, tm + 1, tr);
    merge(t[v << 1].begin(), t[v << 1].end(), t[(v << 1) + 1].begin(),
          t[(v << 1) + 1].end(), back_inserter(t[v]));
  }
}
inline int get(int &l, int &r, int v = 1, int tl = 1, int tr = n) {
  if (l <= tl && tr <= r)
    return t[v].end() - lower_bound(t[v].begin(), t[v].end(), l);
  if (tl > r || tr < l) return 0;
  int tm = tl + tr >> 1;
  return get(l, r, v << 1, tl, tm) + get(l, r, (v << 1) + 1, tm + 1, tr);
}
int main() {
  gets(s);
  q = IN();
  n = (int)strlen(s);
  for (int i = 0; i < n; i++) {
    if (s[i] == '(')
      st.push(i + 1);
    else if (s[i] == ')' && (int)st.size()) {
      dp[i + 1] = st.top();
      st.pop();
    }
  }
  build();
  while (q--) {
    l = IN(), r = IN();
    ans = get(l, r);
    OUT(ans + ans), putchar('\n');
  }
  return 0;
}
