// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <iomanip>
#include <cstdlib>
#include <numeric>
#include <cstdio>
#include <vector>
#include <bitset>
#include <deque>
#include <queue>
#include <cmath>
#include <ctime>
#include <set>
#include <map>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define hashmap unordered_map
#define hashset unordered_set
#define heap priority_queue
#define MS(x, v, n) memset((x), (v), sizeof((x)[0]) * (n))
#define sz(x) int((x).size())
#define all(x) (x).begin(),  (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef unsigned long long ull;

void file(const string FILE = "Test")
{
    freopen((FILE + ".INP").c_str(), "r", stdin);
    freopen((FILE + ".ERR").c_str(), "w", stderr);
    freopen((FILE + ".OUT").c_str(), "w", stdout);
}

template<typename T> bool maxoreq(T &res, const T &val) { if (res <= val) { res = val; return true; } return false; }
template<typename T> bool minoreq(T &res, const T &val) { if (res >= val) { res = val; return true; } return false; }
template<typename T> bool maximize(T &res, const T &val) { if (res < val) { res = val; return true; } return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val) { res = val; return true; } return false; }

const int mvx[] = {0, +1, +0, -0, -1, +1, +1, -1, -1, 0};
const int mvy[] = {0, +0, +1, -1, -0, +1, -1, -1, +1, 0};

/// ====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====

const db EPS = 1e-9;
const db PI = acos(-1);
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
const int LIM = 1e6 + 16;

struct Node
{
    int length;
    int open;
    int close;
    Node (int length = 0, int open = 0, int close = 0)
    : length(length), open(open), close(close) {}

    friend istream &operator >> (istream &cin, Node &a)
    {
        cin >> a.length >> a.open >> a.close;
        return cin;
    }

    friend ostream &operator << (ostream &cout, const Node &a)
    {
        cout << a.length << " " << a.open << " " << a.close;
        return cout;
    }
};

Node operator + (const Node &a, const Node &b)
{
    int extra = min(a.open, b.close);

    Node c;
    c.length = a.length + b.length + extra;
    c.open   = a.open   + b.open   - extra;
    c.close  = a.close  + b.close  - extra;
    return c;
}

struct Segtree
{
    int n;
    vector<Node> t;

    void init(int lim)
    {
        for (n = 1; n < lim; n <<= 1);
        t.assign(n << 1, Node());
    }

    void modify(int p, char c, int ct, int lt, int rt)
    {
        if (rt - lt == 1)
        {
            t[ct] = (c == '(') ? Node(0, 1, 0) : Node(0, 0, 1);
            return ;
        }

        int mt = (lt + rt) >> 1;
        if (mt > p)
            modify(p, c, ct * 2 + 1, lt, mt);
        else
            modify(p, c, ct * 2 + 2, mt, rt);

        t[ct] = t[ct * 2 + 1] + t[ct * 2 + 2];
    }

    void modify(int p, char c)
    {
        return modify(p, c, 0, 0, n);
    }

    Node query(int l, int r, int ct, int lt, int rt)
    {
        if (lt >= r || l >= rt) return Node();
        if (lt >= l && r >= rt) return t[ct];

        int mt = (lt + rt) >> 1;
        Node lv = query(l, r, ct * 2 + 1, lt, mt);
        Node rv = query(l, r, ct * 2 + 2, mt, rt);
        return lv + rv;
    }

    Node query(int l, int r)
    {
        return query(l, r + 1, 0, 0, n);
    }
};

int main()
{
//    file("Test");
    ios::sync_with_stdio(NULL);
    cin.tie(NULL);

    string s;
    cin >> s;

    int n = s.size();
    Segtree S;
    S.init(n + 1);

    for (int i = 1; i <= n; ++i)
        S.modify(i, s[i - 1]);

    int q;
    cin >> q;

    while (q-->0)
    {
        int l, r;
        cin >> l >> r;
        cout << 2 * S.query(l, r).length << "\n";
    }

    return 0;
}
