#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
const int inf = 1034567891;
const long long LL_INF = 1234567890123456789ll;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
template <typename T>
T GCD(T a, T b) {
  long long t;
  while (a) {
    t = a;
    a = b % a;
    b = t;
  }
  return b;
}
template <typename T>
string toString(T a) {
  return to_string(a);
}
template <typename T>
void toInt(string s, T& x) {
  stringstream str(s);
  str >> x;
}
inline int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline int sub(int x, int y) {
  x -= y;
  if (x < 0) x += mod;
  return x;
}
inline int mul(int x, int y) { return (x * 1ll * y) % mod; }
inline int powr(int a, long long b) {
  int x = 1 % mod;
  while (b) {
    if (b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a) { return powr(a, mod - 2); }
const int N = 1e6 + 5;
string str;
int n;
typedef struct Node {
  int open, close, bal;
  Node() : open(0), close(0), bal(0) {}
} node;
node seg[4 * N + 5];
node merge(node node1, node node2) {
  int mn = min(node1.open, node2.close);
  node1.bal += 2 * mn + node2.bal;
  node1.open = node1.open - mn + node2.open;
  node2.close -= mn;
  node1.close += node2.close;
  return node1;
}
void build(int low, int high, int pos) {
  if (low == high) {
    if (str[low] == '(') {
      seg[pos].open++;
    } else {
      seg[pos].close++;
    }
    return;
  }
  int mid = (low + high) >> 1;
  build(low, mid, 2 * pos + 1);
  build(mid + 1, high, 2 * pos + 2);
  seg[pos] = merge(seg[2 * pos + 1], seg[2 * pos + 2]);
}
node query(int low, int high, int l, int r, int pos) {
  if (low > r || high < l) return Node();
  if (low >= l && high <= r) return seg[pos];
  int mid = (low + high) >> 1;
  return merge(query(low, mid, l, r, 2 * pos + 1),
               query(mid + 1, high, l, r, 2 * pos + 2));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> str;
  n = str.size();
  build(0, n - 1, 0);
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    node ans = query(0, n - 1, l, r, 0);
    cout << ans.bal << '\n';
  }
  return 0;
}
