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 lli long long int
#define bakku ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod2 1000000007
#define mod 998244353
#define PI 3.1415926535897932384
#define INF LLONG_MAX
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

//first index greater than key
lli binarysearch(lli arr[], lli l, lli r, lli key)
{
    lli ans = -1; // return -1 if no element is greater than key

    if(arr[r] <= key)
        return (r+1);

    if(arr[l] > key)
        return l;

    while(l <= r)
    {
        lli m = l + (r-l+1)/2;

        if(arr[m] <= key)
            l = m + 1;

        else if(arr[m] > key)
        {
            ans = m;
            r = m - 1;
        }
    }

    return ans;
}

lli max(lli a, lli b)
{
    if(a > b) return a;
    return b;
}

lli min(lli a, lli b)
{
    if(a < b) return a;
    return b;
}

// void dfs(vector<lli> adj[], lli v, lli used[])
// {
//     used[v] = 1;
//     cout << v << " ";

//     for(lli u : adj[v])
//     {
//         if(used[u] == 0)
//             dfs(adj, u, used);
//     }

//     used[v] = 2;
// }

// palindrome
lli pal(string str)
{
    string temp = str;
    reverse(temp.begin(), temp.end());

    if(temp == str)
        return 1;

    return -1;
}

lli maxSubArraySum(lli a[], lli l, lli r) 
{ 
   lli max_so_far = a[l]; 
   lli curr_max = a[l]; 
  
   for(lli i=l+1; i<r-l+1; i++) 
   { 
        curr_max = max(a[i], curr_max+a[i]); 
        max_so_far = max(max_so_far, curr_max); 
   } 
   return max_so_far; 
}

// lli modexp(lli x, lli y, lli mod)  
// {  
//     lli res = 1;     // Initialize result  
  
//     x = x % mod; // Update x if it is more than or  
//                 // equal to p  
  
//     while (y > 0)  
//     {  
//         // If y is odd, multiply x with result  
//         if (y & 1)  
//             res = (res*x) % mod;  
  
//         // y must be even now  
//         y = y>>1; // y = y/2  
//         x = (x*x) % mod;  
//     }  
//     return res;  
// }

lli gcd(lli a, lli b) 
{ 
    // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 

lli lcm(lli a, lli b)
{
    lli x = gcd(a, b);
    lli ans = (a*b)/x;
    return ans;
}

lli ncr(lli n, lli r) 
{ 
  
    // p holds the value of n*(n-1)*(n-2)..., 
    // k holds the value of r*(r-1)... 
    lli p = 1, k = 1; 
  
    // C(n, r) == C(n, n-r), 
    // choosing the smaller value 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
  
            // gcd of p, k 
            lli m = gcd(p, k); 
  
            // dividing by gcd, to simplify product 
            // division by their gcd saves from the overflow 
            p /= m; 
            k /= m; 
  
            n--; 
            r--; 
        } 
  
        // k should be simplified to 1 
        // as C(n, r) is a natural number 
        // (denominator should be 1 ) . 
    } 
  
    else
        p = 1; 
  
    // if our approach is correct p = ans and k =1 
    // cout << p << endl; 

    return p;
}

lli modpow(lli x, lli y, lli p = mod)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
 
lli modadd(lli a, lli b, lli m = mod)
{
    a += b;
    if (a >= m)
        a -= m;
    return a;
}
 
lli modmul(lli a, lli b, lli m = mod)
{
    return ((a % m) * (b % m)) % m;
}
 
lli modi(lli a, lli m = mod) 
{ 
    return modpow(a, m - 2, m); 
}

/*########################################################################*/
/*########################################################################*/
/*########################################################################*/
/*########################################################################*/

int main()
{
    bakku;
    lli testcases = 1;
    // cin >> testcases;
    
    while(testcases--)
    {
        lli k;
        cin >> k;
        
        lli n = pow(2, k);
        
        string s;
        cin >> s;
        
        // reverse(s.begin(), s.end());
        // s.push_back('$');
        // reverse(s.begin(), s.end());
        
        lli a[n];
        fill(a, a+n, 0);
        
        for(lli i=0; i<n/2; i++)
        {
            if(s[i] == '0' || s[i] == '1')
            {
                // a[i+n/2] = 1;
                a[n-1-i] = 1;
            }    
            
            else
            {
                // a[i+n/2] = 2;
                a[n-1-i] = 2;
            }
        }
        
        // lli save = n/4;
        // lli cur = save;
        
        for(lli i=n/2; i<n; i++)
        {
            lli ind = n-1-i;
            
            if(s[i] == '0')
            {
                // a[cur] = a[2*cur];
                a[ind] = a[2*ind + 1];
            }
            
            else if(s[i] == '1')
            {
                // a[cur] = a[2*cur + 1];
                a[ind] = a[2*ind];
            }
            
            else
            {
                // a[cur] = a[2*cur] + a[2*cur+1];
                a[ind] = a[2*ind + 1] + a[2*ind];
            }
            
            // cur++;
            
            // if(save * 2 == cur)
            // {
            //     save/=2;
            //     cur = save;
            // }
        }
        
        // for(lli i=n-1; i>=1; i--)
        // {
        //     cout << i << ": " << a[i] << endl;
        // }
        
        // cout << "*****\n";
        
        lli q;
        cin >> q;
        
        for(lli i=0; i<q; i++)
        {
            lli p; char c;
            
            cin >> p >> c;
            p--;
            
            s[p] = c;
            
            lli ind = n-1-p;
            
            if(s[p] == '0')
            {                
                if(2*ind+1 < n)
                    a[ind] = a[2*ind+1];
                    
                else 
                    a[ind] = 1;                 
            } 
            
            else if(s[p] == '1')
            {
                if(2*ind < n)
                    a[ind] = a[2*ind];
                    
                else
                    a[ind] = 1;
            }
            
            else 
            {
                if(2*ind+1 < n)
                    a[ind] = a[2*ind + 1] + a[2*ind];
                    
                else
                    a[ind] = 2;
            }
            
            ind /= 2;
            
            while(ind != 0)
            {
                p = n-1-ind;
                
                if(s[p] == '0')
                {                
                    if(2*ind+1 < n)
                        a[ind] = a[2*ind+1];
                        
                    else 
                        a[ind] = 1;
                } 
                
                else if(s[p] == '1')
                {
                    if(2*ind < n)
                        a[ind] = a[2*ind];
                        
                    else
                        a[ind] = 1;
                }
                
                else 
                {
                    if(2*ind+1 < n)
                        a[ind] = a[2*ind + 1] + a[2*ind];
                        
                    else
                        a[ind] = 2;
                }         
                
                ind /= 2;       
            }
            
            cout << a[1] << endl;
        }
    }

    return 0;
}