#include <bits/stdc++.h>
using namespace std;
int segment[10000000][3];
void f(int node, string &s, int start, int end) {
  if (start > end) return;
  if (start == end) {
    segment[node][0] = 0;
    segment[node][1] = s[start] == '(' ? 1 : 0;
    segment[node][2] = s[start] == ')' ? 1 : 0;
  } else {
    int mid = (start + end) / 2;
    f(2 * node, s, start, mid);
    f((2 * node + 1), s, mid + 1, end);
    if (segment[2 * node][0] != -1 && segment[2 * node + 1][0] != -1) {
      int diff = min(segment[2 * node][1], segment[2 * node + 1][2]);
      segment[node][0] = segment[2 * node][0] + segment[2 * node + 1][0] + diff;
      segment[node][1] = segment[2 * node + 1][1] + segment[2 * node][1] - diff;
      segment[node][2] = segment[2 * node][2] + segment[2 * node + 1][2] - diff;
    } else if (segment[2 * node][0] == -1) {
      segment[node][0] = segment[2 * node + 1][0];
      segment[node][1] = segment[2 * node + 1][1];
      segment[node][2] = segment[2 * node + 1][2];
    } else if (segment[2 * node + 1][0] == -1) {
      segment[node][0] = segment[2 * node][0];
      segment[node][1] = segment[2 * node][1];
      segment[node][2] = segment[2 * node][2];
    }
  }
}
pair<int, pair<int, int> > find(int node, int start, int end, int x, int y) {
  if (y < start || x > end) {
    return make_pair(0, make_pair(0, 0));
  }
  if (start >= x && end <= y) {
    return make_pair(segment[node][0],
                     make_pair(segment[node][1], segment[node][2]));
  }
  int mid = (start + end) / 2;
  pair<int, pair<int, int> > p1 = find(2 * node, start, mid, x, y);
  pair<int, pair<int, int> > p2 = find(2 * node + 1, mid + 1, end, x, y);
  int diff = min(p1.second.first, p2.second.second);
  int v1 = p1.first + p2.first + diff;
  int v2 = p1.second.first + p2.second.first - diff;
  int v3 = p1.second.second + p2.second.second - diff;
  return make_pair(v1, make_pair(v2, v3));
}
int main() {
  memset(segment, -1, sizeof(segment));
  string s;
  cin >> s;
  f(1, s, 0, s.length() - 1);
  int N;
  cin >> N;
  int arr[N];
  for (int i = 0; i < N; ++i) {
    int x, y;
    cin >> x >> y;
    cout << 2 * find(1, 0, s.length() - 1, x - 1, y - 1).first << endl;
  }
  return 0;
}
