#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, -1, 0};
int dy[] = {1, 0, 0, -1};
long double PI = 3.14159265358979323846264338327950;
const int N = (1e6 + 10) * 4, M = 1e7;
struct Node {
  int open, close, mx;
};
Node SegmentTree[N];
string s;
int n;
void build(int st = 0, int end = n - 1, int root = 1) {
  if (st == end) {
    SegmentTree[root].open = (s[st] == '(');
    SegmentTree[root].close = (s[st] == ')');
    SegmentTree[root].mx = 0;
    return;
  }
  build(st, ((end + st) >> 1), (root << 1));
  build(((end + st) >> 1) + 1, end, ((root << 1) | 1));
  Node x = SegmentTree[(root << 1)], y = SegmentTree[((root << 1) | 1)];
  Node& ret = SegmentTree[root];
  int add = min(x.open, y.close);
  ret.mx = x.mx + y.mx + add;
  ret.open = x.open - add + y.open;
  ret.close = y.close - add + x.close;
}
Node query(int l, int r, int st = 0, int end = n - 1, int root = 1) {
  Node ret;
  ret.open = ret.mx = ret.close = 0;
  if (l > end || r < st) {
    return ret;
  }
  if (st >= l && end <= r) {
    return SegmentTree[root];
  }
  Node x = query(l, r, st, ((end + st) >> 1), (root << 1)),
       y = query(l, r, ((end + st) >> 1) + 1, end, ((root << 1) | 1));
  int add = min(x.open, y.close);
  ret.mx = x.mx + y.mx + add;
  ret.open = x.open - add + y.open;
  ret.close = y.close - add + x.close;
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> s;
  n = (int)s.size();
  build();
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    cout << (query(l, r).mx << 1) << "\n";
  }
}
