#include <bits/stdc++.h>
using namespace std;
struct Node {
  int optimal;
  int open;
  int close;
};
const int N = 1e6 + 1;
Node inteval[4 * N];
string s;
Node operator+(const Node& left, const Node& right) {
  Node res;
  int temp = min(left.open, right.close);
  res.optimal = left.optimal + right.optimal + temp;
  res.close = left.close + right.close - temp;
  res.open = left.open + right.open - temp;
  return res;
}
void build(int idx, int l, int r) {
  if (l == r) {
    if (s[l] == '(')
      inteval[idx] = Node{0, 1, 0};
    else
      inteval[idx] = Node{0, 0, 1};
    return;
  }
  int mid = (l + r) / 2;
  build(idx * 2, l, mid);
  build(idx * 2 + 1, mid + 1, r);
  inteval[idx] = inteval[idx * 2] + inteval[idx * 2 + 1];
}
Node query(int idx, int l, int r, int u, int v) {
  if (l > v || r < u) {
    return Node{0, 0, 0};
  }
  if (u <= l && r <= v) {
    return inteval[idx];
  }
  int mid = (l + r) / 2;
  return query(idx * 2, l, mid, u, v) + query(idx * 2 + 1, mid + 1, r, u, v);
}
int main() {
  cin >> s;
  int n = s.size(), test, u, v;
  build(1, 0, n - 1);
  cin >> test;
  while (test--) {
    cin >> u >> v;
    cout << query(1, 0, n - 1, u - 1, v - 1).optimal * 2 << endl;
  }
  return 0;
}
