#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, y, x, ans1, ans2, sum, lo, hi, an2s, q, flag, m;
long long inf = 1000000000000000000;
long long dp[2005][2005];
long long b[4030005], a[4000005], t[4000005], o[4000005], c[4000005];
map<long long, long long> m1, m2;
pair<long long, pair<long long, long long>> p2[200005];
vector<long long> v;
vector<long long>::iterator itr, itr1, itr2;
string s;
long long mod = 1e9 + 7;
void build(int id = 1, int l = 0, int r = n) {
  if ((r - l) < 2) {
    if (s[l] == '(') {
      o[id] = 1;
    } else {
      c[id] = 1;
    }
    return;
  }
  int mid = (l + r) / 2;
  build(2 * id, l, mid);
  build((2 * id + 1), mid, r);
  int temp = min(o[2 * id], c[2 * id + 1]);
  t[id] = t[2 * id] + t[2 * id + 1] + temp;
  o[id] = o[2 * id] + o[2 * id + 1] - temp;
  c[id] = c[2 * id] + c[2 * id + 1] - temp;
}
pair<int, pair<int, int>> query(int x, int y, int id = 1, int l = 0,
                                int r = n) {
  if (l >= y || x >= r) {
    return make_pair(0, make_pair(0, 0));
  }
  if (x <= l && r <= y) {
    return make_pair(t[id], make_pair(o[id], c[id]));
  }
  int mid = (l + r) / 2;
  pair<int, pair<int, int>> a = query(x, y, 2 * id, l, mid);
  pair<int, pair<int, int>> b = query(x, y, 2 * id + 1, mid, r);
  int temp = min(a.second.first, b.second.second);
  int T = a.first + b.first + temp;
  int O = a.second.first + b.second.first - temp;
  int C = a.second.second + b.second.second - temp;
  return make_pair(T, make_pair(O, C));
}
int testc;
int main() {
  cin >> s;
  n = s.size();
  cin >> testc;
  build(1, 0, n);
  while (testc--) {
    int X, Y;
    cin >> X >> Y;
    cout << 2 * query((X - 1), (Y)).first << endl;
  }
}
