Problem: 2^k teams participate in a playoff tournament. The tournament consists of 2^k - 1 games. They are held as follows: first of all, the teams are split into pairs: team 1 plays against team 2, team 3 plays against team 4 (exactly in this order), and so on (so, 2^{k-1} games are played in that phase). When a team loses a game, it is eliminated, and each game results in elimination of one team (there are no ties). After that, only 2^{k-1} teams remain. If only one team remains, it is declared the champion; otherwise, 2^{k-2} games are played: in the first one of them, the winner of the game "1 vs 2" plays against the winner of the game "3 vs 4", then the winner of the game "5 vs 6" plays against the winner of the game "7 vs 8", and so on. This process repeats until only one team remains.

For example, this picture describes the chronological order of games with k = 3:

<image>

Let the string s consisting of 2^k - 1 characters describe the results of the games in chronological order as follows:

  * if s_i is 0, then the team with lower index wins the i-th game; 
  * if s_i is 1, then the team with greater index wins the i-th game; 
  * if s_i is ?, then the result of the i-th game is unknown (any team could win this game). 



Let f(s) be the number of possible winners of the tournament described by the string s. A team i is a possible winner of the tournament if it is possible to replace every ? with either 1 or 0 in such a way that team i is the champion.

You are given the initial state of the string s. You have to process q queries of the following form: 

  * p c — replace s_p with character c, and print f(s) as the result of the query. 

Input

The first line contains one integer k (1 ≤ k ≤ 18).

The second line contains a string consisting of 2^k - 1 characters — the initial state of the string s. Each character is either ?, 0, or 1.

The third line contains one integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of queries.

Then q lines follow, the i-th line contains an integer p and a character c (1 ≤ p ≤ 2^k - 1; c is either ?, 0, or 1), describing the i-th query.

Output

For each query, print one integer — f(s).

Example

Input


3
0110?11
6
5 1
6 ?
7 ?
1 ?
5 ?
1 1


Output


1
2
3
3
5
4

Solution (in CPP):

Solution:
// I may be weak, but not long enough
#include <bits/stdc++.h>
using namespace std;
#define int long long  
enum {Master, Minato}; 
const long long MOD = 1e9 + 7ll, MAXN = 6e5 + 5, INF = 2e18;
// #include "dbg_s1.cpp"
class Node { public :
    char C; 
    int W; 
    Node() { 
        C = '$';
        W = 0;  
    }
    Node operator=(Node const &x) {
        C = x.C;
        W = x.W; 
    }
}; 
Node tr[4 * MAXN], avoid; 
int link[MAXN], par[MAXN], n, k; 
vector<int> idx{0, 1, 2}; 
map<char, int> ci{{'0', 0}, {'1', 1}, {'?', 2}}; 
map<int, char> ic{{0, '0'}, {1, '1'}, {2, '2'}}; 
Node merge(Node a, Node b) {
    Node c; 
    c.W = a.W + b.W; 
    return c;
}
void setit(int c) {
    if (tr[c].C == '0') {
        tr[c].W = tr[2 * c].W; 
    } else if (tr[c].C == '1') {
        tr[c].W = tr[2 * c + 1].W; 
    } else {
        tr[c].W = tr[2 * c].W + tr[2 * c + 1].W; 
    }
}
bool leaf(int c) {
    if (c >= (1 << (k - 1)) and c < (1 << k)) {
        return true; 
    }
    return false; 
}
void buildx(int c, int l, int r) {
    if (leaf(c)) {
        setit(c); 
        return; 
    }  
    int md = (l + r) / 2;
    buildx(2 * c, l, md); 
    buildx(2 * c + 1, md + 1, r); 
    par[2 * c] = c; 
    par[2 * c + 1] = c;  
    setit(c); 
} 
void updatex(int c, int id, char val) {
    if (c) {
        if (c == id) {
            tr[c].C = val; 
        }
        setit(c);
        updatex(c / 2, id, val); 
    }
    // tle krta hai motherboard
    // if (c == id) {
    //     tr[c].C = val; 
    //     setit(c); 
    // } else if (leaf(c)) {
    //     return; 
    // } else {
    //     int md = (l + r) / 2; 
    //     updatex(2 * c, l, md, id, val); 
    //     updatex(2 * c + 1, md + 1, r, id, val); 
    //     setit(c); 
    // }
}
void update(int id, char v) {
    updatex(id, id, v); 
}
void build() {
    buildx(1, 1, n); 
}
void init() {
    avoid.C = '$';
    avoid.W = 0;  
    for (int i = 0; i < 4 * MAXN; i++) {
        tr[i] = avoid; 
    }
}
void Solution() {
    cin >> k; 
    string s; 
    cin >> s;  
    int sn = (1 << k) - 1;  
    n = 1 << (k - 1);  
    string s2 = s; 
    vector<int> a(sn), a2(sn);  
    iota(a.begin(), a.end(), 1);
    iota(a2.begin(), a2.end(), 1); 
    reverse(s.begin(), s.end()); 
    reverse(a2.begin(), a2.end()); 
    for (int i = 0; i <= k - 1; i++) {
        int st = (1 << i) - 1, en = st + (1 << i); // [st, en)
        reverse(s.begin() + st, s.begin() + en);
        reverse(a2.begin() + st, a2.begin() + en); 
    }
    for (int i = 0; i < sn; i++) {
        link[a2[i]] = a[i]; 
    }   
    for (int i = 1; i <= sn; i++) {
        tr[i].C = s[i - 1]; 
        tr[i].W = 0; 
    }
    for (int i = 0; i < (1 << k); i++) {
        tr[(1 << k) + i].W = 1;  
    }
    build();     
    int q; 
    cin >> q; 
    while (q--) {
        int idx;
        char ch; 
        cin >> idx >> ch;
        idx = link[idx]; 
        update(idx, ch);  
        cout << tr[1].W << '\n';  
    }
}
signed main() 
{
    ios::sync_with_stdio(0); cin.tie(0);
    int tt = 1;
    // cin >> tt; 
    for (int tc = 1; tc <= tt; tc++) {
        Solution(); 
    }
    return 0;
}