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:


#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vc vector<char>
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define ss second
#define ff first
#define ll long long
#define int ll
#define popcount(x) __builtin_popcountll(x)
#define pii pair<int , int>
#define vpi vector<pii>
#define arr array
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define EACH(x, a) for (auto& x: a)



// #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) \
    for ( \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second; \
        debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
)

template <typename T>inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif


template<class T> bool selfmax(T& a, const T& b) {
    int to_ret = 0;
    if (a < b)to_ret = 1;
    a = max(a , b);
    return to_ret;
}
template<class T> bool selfmin(T& a, const T& b) {
    int to_ret = 0;
    if (a > b)to_ret = 1;
    a = min(a , b);
    return to_ret;
}

template<typename... T>
void read(T&... args) {
	((cin >> args), ...);
}

template<class A> void read(vector<A>& x) {
	EACH(a, x)
		read(a);
}
template<class A> void read(vector<pair<A , A > >& x) {
	EACH(a, x)
		read(a.ff , a.ss);
}

template<typename... T>
void read(vi &a ){
	int n = a.size();
	for (int i = 0 ; i < n ; i++)cin >> a[i];
}

template<class A>void print(vector<A>& a){
    EACH(x , a)cout << x << " ";
    cout << endl;
}

long long prod(long long a, long long b, long long m)
{
    long long res = 0;

    while(b)
    {
        if(b & 1)
            res = (res + a) % m;
        a = (a + a) % m;

        b >>= 1;
    }

    return res;
}

long long power(long long a, long long b, long long m)
{
    long long res = 1;

    while(b)
    {
        if(b & 1)
            res = prod(res, a, m);
        a = prod(a, a, m);

        b >>= 1;
    }

    return res;
}

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1}; //4 Direction
// char dc[] = {'D' , 'R' , 'U' , 'L'};

// int dx[]={1,1,0,-1,-1,-1,0,1};
// int dy[]={0,1,1,1,0,-1,-1,-1};  // 8D

const int MOD = 1e9+7;
const int INF = 1000000000;
const int BIGINF = 1e12;

void solve(){
    
    int k;
    read(k);
    string s;
    read(s);
    int strt = 1;
    // a here represents the games
    vvi a((1<<k ));
    for (int i = 0 ; i < k-1 ; i++){
        
        int cnt = 0 , last = strt+(1<<(k-1-i));
        
        while (cnt != 1<<(k-1-i)){
            a[strt+cnt].pb(last);
            a[strt+cnt+1].pb(last++);
            cnt+=2;
        }
        
        strt += 1<<(k-1-i);
    }
    // debug(a);
    vi top_val((1<<k ) ) , bot_val ((1<<k ));
    for (int i = 1 ; i <= ((1<<(k-1))) ; i++){
        top_val[i] = 1;
        bot_val[i] = 1;
    }
    // debug(top_val , bot_val);
    for (int i = 0 ; i < s.size()-1 ; i+=2){
        
        if (s[i] == '0'){
            top_val[a[i+1][0]] = top_val[i+1];
        }
        else if (s[i] == '1'){
            top_val[a[i+1][0]] = bot_val[i+1];
        }
        else{
            top_val[a[i+1][0]] = top_val[i+1] + bot_val[i+1];
        }
        
        if (s[i+1] == '0'){
            bot_val[a[i+1][0]] = top_val[i+2];
        }
        else if (s[i+1] == '1'){
            bot_val[a[i+1][0]] = bot_val[i+2];
        }
        else{
            bot_val[a[i+1][0]] = bot_val[i+2] + top_val[i+2];
        }
    }
    
    // debug(top_val , bot_val);
    int q;
    read(q);
    while (q--){
        int p ;
        char c;
        read(p , c);
        s[p-1] = c;
        
        int pp = p;
        while (pp != (1<<k)-1){
            if (pp%2 == 0){
                if (s[pp-1] == '1'){
                    bot_val[a[pp][0]] = bot_val[pp];
                }
                else if (s[pp-1]=='0'){
                    bot_val[a[pp][0]] = top_val[pp];
                }
                else{
                    bot_val[a[pp][0]] = top_val[pp] + bot_val[pp];
                }
            }
            else{
                if (s[pp-1] == '1'){
                    top_val[a[pp][0]] = bot_val[pp];
                }
                else if (s[pp-1]=='0'){
                    top_val[a[pp][0]] = top_val[pp];
                }
                else{
                    top_val[a[pp][0]] = top_val[pp] + bot_val[pp];
                }
            }
            pp = a[pp][0];
        }
        // s[p] = 
        if (s.back() == '1'){
            cout << bot_val.back() << endl;
        }
        else if (s.back() == '0'){
            cout << top_val.back() << endl;
        }
        else{
            cout << top_val.back() + bot_val.back() << endl;
        }
        // debug(top_val , bot_val);
    }
}

int32_t main(){

    // #ifndef ONLINE_JUDstartGE
    // // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    

    for (int tt = 0 ; tt < t ; tt++){
        // cout << "Case #" << (tt+1) <<": ";
        // time__("Solve")
        solve();
    }
}