#include <bits/stdc++.h>
using namespace std;
const int Len = 2333333;
char buf[Len], *p1 = buf, *p2 = buf, duf[Len], *q1 = duf;
inline char gc();
inline int rd();
inline void pc(char c);
inline void rt(int x);
inline void flush();
template <class T>
inline T Max(T a, T b) {
  return a > b ? a : b;
}
template <class T>
inline T Min(T a, T b) {
  return a < b ? a : b;
}
int n, m, l, r, pr, pv;
char s[1000005];
struct tree {
  int l, r, lv, rv, v;
} a[1000005 << 2];
inline void Upd(int u) {
  int t = Min(a[u << 1].rv, a[u << 1 ^ 1].lv);
  a[u].v = a[u << 1].v + a[u << 1 ^ 1].v + t,
  a[u].lv = a[u << 1].lv + a[u << 1 ^ 1].lv - t,
  a[u].rv = a[u << 1 ^ 1].rv + a[u << 1].rv - t;
}
void build(int u, int l, int r) {
  a[u].l = l, a[u].r = r;
  if (l == r) return void(s[l] == '(' ? a[u].rv = 1 : a[u].lv = 1);
  int mid = (l + r) >> 1;
  build(u << 1, l, mid), build(u << 1 ^ 1, mid + 1, r), Upd(u);
}
void Query(int u) {
  if (a[u].r < l || a[u].l > r) return;
  if (l <= a[u].l && a[u].r <= r) {
    int t = Min(pr, a[u].lv);
    return void((pv += a[u].v + t, pr = a[u].rv + pr - t));
  }
  Query(u << 1), Query(u << 1 ^ 1);
}
int main() {
  scanf("%s", s + 1), n = strlen(s + 1), scanf("%d", &m);
  build(1, 1, n);
  while (m--) l = rd(), r = rd(), pr = pv = 0, Query(1), rt(pv << 1), pc('\n');
  return flush(), 0;
}
inline char gc() {
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, Len, stdin), p1 == p2)
             ? -1
             : *p1++;
}
inline int rd() {
  char c;
  while (!isdigit(c = gc()) && c != '-')
    ;
  int f = c == '-' ? c = gc(), 1 : 0, x = c ^ 48;
  while (isdigit(c = gc())) x = ((x + (x << 2)) << 1) + (c ^ 48);
  return f ? -x : x;
}
inline void pc(char c) {
  q1 == duf + Len &&fwrite(q1 = duf, 1, Len, stdout), *q1++ = c;
}
inline void rt(int x) {
  x < 0 ? pc('-'), x = -x : 0, pc((x >= 10 ? rt(x / 10), x % 10 : x) + 48);
}
inline void flush() { fwrite(duf, 1, q1 - duf, stdout); }
