#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
struct node {
  int x, y, id;
  bool operator<(const node &m) const { return y < m.y; }
};
int c[N] = {0}, n, ans[100000 + 10];
char s[N];
void add(int x, int val) {
  while (x <= n) {
    c[x] += val;
    x += x & (-x);
  }
}
int sum(int x) {
  int ans = 0;
  while (x > 0) {
    ans += c[x];
    x -= x & (-x);
  }
  return ans;
}
int main() {
  cin >> (s + 1);
  n = strlen(s + 1);
  int q;
  cin >> q;
  vector<node> a(q);
  for (int i = 0; i < q; i++) {
    cin >> a[i].x >> a[i].y;
    a[i].id = i;
  }
  sort(a.begin(), a.end());
  stack<int> ss;
  int r = 1;
  for (int i = 0; i < q;) {
    if (r <= a[i].y) {
      if (s[r] == '(')
        ss.push(r);
      else {
        if (!ss.empty()) {
          int p = ss.top();
          add(p, 1);
          ss.pop();
        }
      }
      r++;
    } else {
      ans[a[i].id] = (sum(a[i].y) - sum(a[i].x - 1)) * 2;
      i++;
    }
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
