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>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
using  namespace std;
// using namespace __gnu_pbds;

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Give shorthand names to data types using typedef.
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int>  pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef pair<ll, ll> pll;
typedef vector<ll>  vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef pair<ll,pair<ll,ll>> triplet;
// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<=n;i++)
#define Fo(i,n) for(i=0;i<n;i++)
#define Fo1(i,n) for(i=1;i<=n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)
#define Rep(i,a,b) for(i=a;i<=b;i++)
#define Rep2(i,a,b) for(i=a;i>=b;i--)

#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define set_bits __builtin_popcountll

#define PI 3.1415926535897932384626

#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
mt19937 rnd((unsigned int) chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int MOD3 = 1610612741;
/* Alternate Prime nos where probability of collision is less for hashing for MOD3:
    long long:
    1000000000039
    2000000000003
    3000000000013
    4000000000039
    int:
    1610612741(currently used).
*/
const ll INF = 1e18;
const ll NINF = -1e18;


#define deb(x) cerr << #x <<" "; _print(x); cerr << endl;

template <class T> void _print(T x){cerr<<x;}
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.F); cerr << ","; _print(p.S); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll mpow(ll base, ll exp , ll mod) { base %= mod; ll result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % mod; base = (base * base) % mod; exp >>= 1;} return result;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return mpow(a, b - 2, b);}
bool revsort(ll a, ll b) {return a > b;}
void swap(int &x, int &y) {int temp = x; x = y; y = temp;}
ll combination(ll n, ll r, ll m, ll *fact, ll *ifact) {ll val1 = fact[n]; ll val2 = ifact[n - r]; ll val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;}
void google(int t) {cout << "Case #" << t << ": ";}
vector<ll> sieve(int n) {vector<int> arr(n+1); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m
ll phin(ll n) {ll number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (ll i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N))
vector<long long> computeHash(string &s) {ll str_len=s.length(); ll p_pow[str_len]; ll p=123; p_pow[0]=1; for(int i=1;i<str_len;i++) p_pow[i]=(p_pow[i-1]*p)%MOD3; vector<long long> hash(str_len+1); hash[0]=0; for(int i=1;i<=str_len;i++) hash[i] = ( hash[i-1] + ((s[i-1]-'a'+1)*p_pow[i-1]) %MOD3 )%MOD3; return hash; }
vector<int> makeZarray(string s) {int n = s.length(); vector<int> z(n); int l=0,r=0; for(int i=1;i<n;i++) {if(i<=r) z[i] = min(z[i-l],r-i+1); while(i+z[i]<n && s[z[i]]==s[i+z[i]]) z[i]++; if(i+z[i]-1 > r) l=i , r=i+z[i]-1; } return z; }
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

int32_t main()
{
    fast_io;
    int t=1; 
    //cin>>t;
    
    while(t--)
    {
        int k; cin>>k;
        int n = (1<<k);

        string s; cin>>s;
        reverse(all(s));

        vi segTree(2*n,1);

        auto upd = [&](int i){
            return segTree[i] = (s[i]!='0'? segTree[2*i+1]:0) + (s[i]!='1'? segTree[2*i+2]:0);
        };

        rep2(i,n-2,0) upd(i);
        
        int q; cin>>q;

        while(q--)
        {
            int p; char c;
            cin>>p>>c;

            p = n-p-1;
            s[p]=c;

            while(p)
            {
                upd(p);
                p = (p-1)/2;
            }
            cout<<upd(0)<<endl;
        }
        
        cout<<endl;
    }
}