#include <bits/stdc++.h>
using namespace std;
char s[1000002];
int n, m, dp[3][22][1000002] = {0}, ml[100005], mr[100005];
int main(int argc, char **argv) {
  std::ios::sync_with_stdio(false);
  cin >> (s + 1);
  cin >> m;
  for (int i = 1; i <= m; i++) cin >> ml[i] >> mr[i];
  n = strlen(s + 1);
  for (int i = 0; i < 22; i++) {
    for (int j = 1; j + (1 << i) - 1 <= n; j++) {
      if (i == 0) {
        if (s[j] == ')') dp[0][0][j] = 1;
        if (s[j] == '(') dp[1][0][j] = 1;
      } else {
        if (dp[1][i - 1][j] <= dp[0][i - 1][j + (1 << (i - 1))]) {
          dp[0][i][j] = dp[0][i - 1][j] + dp[0][i - 1][j + (1 << (i - 1))] -
                        dp[1][i - 1][j];
          dp[1][i][j] = dp[1][i - 1][j + (1 << (i - 1))];
        } else {
          dp[0][i][j] = dp[0][i - 1][j];
          dp[1][i][j] = dp[1][i - 1][j + (1 << (i - 1))] + dp[1][i - 1][j] -
                        dp[0][i - 1][j + (1 << (i - 1))];
        }
        dp[2][i][j] = dp[2][i - 1][j] + dp[2][i - 1][j + (1 << (i - 1))];
        dp[2][i][j] += min(dp[1][i - 1][j], dp[0][i - 1][j + (1 << (i - 1))]);
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    int l = ml[i], lb = 0, rb = 0, r = mr[i], cnt = 0, len = r - l + 1;
    if (l == r)
      cout << 0 << endl;
    else {
      for (int i = 0; i <= 22; i++) {
        if (len & (1 << i)) {
          r -= (1 << i);
          cnt += dp[2][i][r + 1];
          if (i == 0) {
            lb = dp[0][i][r + 1];
            rb = dp[1][i][r + 1];
          } else {
            cnt += min(dp[1][i][r + 1], lb);
            if (dp[1][i][r + 1] > lb) {
              rb += dp[1][i][r + 1] - lb;
              lb = dp[0][i][r + 1];
            } else
              lb = dp[0][i][r + 1] + lb - dp[1][i][r + 1];
          }
        }
      }
      cout << cnt * 2 << endl;
    }
  }
  return 0;
}
