#include <bits/stdc++.h>
using namespace std;
struct cell {
  int p;
  int open;
  int close;
};
cell newCell() {
  cell nc;
  nc.p = nc.open = nc.close = 0;
  return nc;
}
const int MAX_N = 1000005;
int n;
cell arr[2 * MAX_N];
cell combine(cell c1, cell c2) {
  int t = min(c1.open, c2.close);
  cell nc;
  nc.p = c1.p + c2.p + t;
  nc.open = c1.open + c2.open - t;
  nc.close = c1.close + c2.close - t;
  return nc;
}
void build() {
  for (int i = n - 1; i > 0; i--) {
    arr[i] = combine(arr[i << 1], arr[i << 1 | 1]);
  }
}
cell query(int l, int r) {
  cell resl = newCell(), resr = newCell();
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) resl = combine(resl, arr[l++]);
    if (r & 1) resr = combine(arr[--r], resr);
  }
  return combine(resl, resr);
}
int main() {
  string s;
  cin >> s;
  n = s.size();
  for (int i = 0; i < s.size(); i++) {
    cell nc = newCell();
    char c = s[i];
    if (c == '(') {
      nc.open = 1;
    } else {
      nc.close = 1;
    }
    arr[i + n] = nc;
  }
  build();
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    cell result = query(a - 1, b);
    printf("%d\n", result.p * 2);
  }
  return 0;
}
